Expect
The @japa/expect
plugin is a wrapper on top of
jest-expect. Please read the Jest documentation to view the methods available on the expect
object.
Suppose you have not configured the plugin during the initial setup. Then, you can install it from the npm registry as follows.
npm i -D @japa/expect@2.0.2
And register it as a plugin within the bin/test.js
file.
import { expect } from '@japa/expect'
import { configure, processCliArgs } from '@japa/runner'
configure({
...processCliArgs(process.argv.slice(2)),
...{
files: ['tests/**/*.spec.js'],
plugins: [expect()]
}
})
const { expect } = require('@japa/expect')
const { configure, processCliArgs } = require('@japa/runner')
configure({
...processCliArgs(process.argv.slice(2)),
...{
files: ['tests/**/*.spec.js'],
plugins: [expect()]
}
})
Once done. You can access the expect
property from the
Test context as follows.
test('add two numbers', ({ expect }) => {
expect(2 + 2).toEqual(4)
})
In Jest, the expect
property is available globally. However, with Japa, we recommend you always read it from the Test context.