Additional Jest matchers for TestDouble
npm i jest-testdouble expect --save-dev # "expect" is a peer dependency required for jest-testdouble to work
or
yarn add jest-testdouble expect --dev # "expect" is a peer dependency required for jest-testdouble to work
From Jest test helper (we recommend to use setupTestFrameworkScriptFile)
const td = require('testdouble');
const jestTestDouble = require('jest-testdouble');
jestTestDouble(td);
global.td = td;
This package add Jest matchers for TestDouble. Fallback to Jest matcher if the expect value
is Jest mock/spy.
- [not].toHaveBeenCalled (alias [not].toBeCalled)
- [not].toHaveBeenCalledWith (alias [not].toBeCalledWith)
- [not].toHaveBeenCalledTimes (alias [not].toBeCalledTimes)
- [not].toHaveBeenLastCalledWith (alias [not].lastCalledWith)
- [not].toHaveBeenNthCalledWith (alias [not].nthCalledWith)
const drink = td.func('drink');
drink('beer');
expect(drink).toHaveBeenCalledWith('beer');
// Fallback to Jest matcher if expect value is Jest mock function
const eat = jest.eat('eat');
eat('rice');
expect(eat).toHaveBeenCalledWith('rice');
jest-testdouble
requires the expect
package to work. You just need to install it
npm i expect --save-dev
or
yarn add expect --dev