Skip to content

Commit fb234fc

Browse files
committed
Troubleshoot canvas test warning messages in jest.
1 parent 4f170d5 commit fb234fc

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
"setupFiles": [ "./test/setup.js" ],
23
"moduleFileExtensions": [
34
"js",
45
"json",

package-lock.json

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"html-webpack-plugin": "^3.2.0",
4949
"jest": "^23.6.0",
5050
"jest-serializer-vue": "^2.0.2",
51+
"sinon": "^7.2.2",
5152
"uglifyjs-webpack-plugin": "^1.3.0",
5253
"vue-jest": "^3.0.0",
5354
"vue-loader": "^15.4.2",

test/setup.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sinon from 'sinon';
2+
3+
const createElement = global.document.createElement;
4+
const FAKECanvasElement = {
5+
getContext: jest.fn(() => {
6+
return {
7+
fillStyle: null,
8+
fillRect: jest.fn(),
9+
drawImage: jest.fn(),
10+
getImageData: jest.fn(),
11+
};
12+
}),
13+
};
14+
15+
/**
16+
* Using Sinon to stub the createElement function call with the original method
17+
* unless we match the 'canvas' argument. If that's the case, return the Fake
18+
* Canvas object.
19+
*/
20+
sinon.stub(global.document, 'createElement')
21+
.callsFake(createElement)
22+
.withArgs('canvas')
23+
.returns(FAKECanvasElement);

0 commit comments

Comments
 (0)