8000 GitHub - lytc/jest-testdouble: Additional Jest matchers for testdouble
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

lytc/jest-testdouble

Repository files navigation

Additional Jest matchers for TestDouble

Build Status npmjs

Installation

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

Configuration

From Jest test helper (we recommend to use setupTestFrameworkScriptFile)

const td = require('testdouble');
const jestTestDouble = require('jest-testdouble');

jestTestDouble(td);

global.td = td;

Usage

This package add Jest matchers for TestDouble. Fallback to Jest matcher if the expect value is Jest mock/spy.

Matchers

  • [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)

Example

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');

Cannot find module 'expect/build/spyMatchers' from 'index.js' error

jest-testdouble requires the expect package to work. You just need to install it

npm i expect --save-dev

or

yarn add expect --dev
< 5C3C div class="BorderGrid-cell">

About

Additional Jest matchers for testdouble

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0