jest-generator
Testing generators are verbose as they require calling next
method of generator each time you want to iterate. jest-generator
encapsulates all iteration and assertion logic itself. It provides easy and readable API for testing generator functions.
Installation
yarn add --dev jest-generator
or
npm install --save-dev jest-generator
Setup
setupTestFrameworkScriptFile
config
Via Add jest-generator
to your Jest setupTestFrameworkScriptFile
configuration
"jest":
setupTest
script
Via Require jest-generator
from setupTest script
// ./setupTest.js ;
Then add this config
"jest":
Usage
// ./pay.js { ; ; return ;}
// ./pay.test.js ; ;
Usage with other libraries
Usage with Saga
// ./books.js { try const response = catch error }
// ./books.test.js ; ; ;
API
Matches iterator against given yield values
In order to return value from yield, simply pass your return value as second array value
{ const response = } const mockResponse = {};const iterator = ;
In order to throw error from yield, you should simply pass Error
instance to return type
{ const response = } const mockErrorResponse = 'network error';const iterator = ;
Licence
This project is licensed under the MIT License - see the LICENSE file for details