Expect

Expect

The @japa/expect plugin is a wrapper on top of jest-expect. Please reference Jest documentation to view the list of available assertion methods.

Installation

Install the package from the npm packages registry as follows.

npm i -D @japa/expect

And register it as a plugin within the entry point file, i.e. (bin/test.js)

import { expect } from '@japa/expect'
import { configure } from '@japa/runner'
configure({
files: ['tests/**/*.spec.js'],
plugins: [expect()]
})

Once done. You can access the expect property from the Test context as follows.

In Jest, the expect property is available globally. However, with Japa, we recommend you always read it from the Test context.

test('add two numbers', ({ expect }) => {
expect(2 + 2).toEqual(4)
})

On this page