Mock
canvas
when run unit test cases with jest. Reference.
This should only be installed as a development dependency (devDependencies
) as it is only designed for testing.
npm i --save-dev jest-canvas-mock
In your package.json
under the jest
, create a setupFiles
array and add jest-canvas-mock
to the array.
{
"jest": {
"setupFiles": ["jest-canvas-mock"]
}
}
If you already have a setupFiles
attribute you can also append jest-canvas-mock
to the array.
{
"jest": {
"setupFiles": ["./__setups__/other.js", "jest-canvas-mock"]
}
}
More about in configuration section.
Alternatively you can create a new setup file which then requires this module or
add the require
statement to an existing setup file.
__setups__/canvas.js
import 'jest-canvas-mock';
// or
require('jest-canvas-mock');
Add that file to your setupFiles
array:
"jest": {
"setupFiles": [
"./__setups__/canvas.js"
]
}
MIT@hustcc.