The assert
object is an instance of chaijs/assert, passed to each test as a property of the test
callback context.
To make your tests more reliable, you can also plan assertions to be executed for a given test. Let’s consider this example:
test('must throw exception', async ({ assert }) => {
try {
await badOperation()
} catch ({ message }) {
assert.equal(message, 'Some error message')
}
})
The above test passes even if an exception was never thrown and no assertions were run. This is a bad test, passing only because we structured it poorly.
To overcome this scenario, plan
for your expected number of assertions:
test('must throw exception', async ({ assert }) => {
assert.plan(1)
try {
await badOperation()
} catch ({ message }) {
assert.equal(message, 'Some error message')
}
})
In the above example, if badOperation
doesn’t throw an exception, the test still fails since we planned for 1
assertion and 0
were made.