Skip to content

Instantly share code, notes, and snippets.

@yan130
Created March 29, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yan130/386d6c79d975de580c8c343a0423b66d to your computer and use it in GitHub Desktop.
Save yan130/386d6c79d975de580c8c343a0423b66d to your computer and use it in GitHub Desktop.
enzyme react.js test CanvasPattern/screen not defined.
import { JSDOM } from 'jsdom';
// "jsdom": "11.1.0",
process.env.NODE_ENV = 'test';
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
global.window = dom.window;
window.screen ={
availWidth: 1024, availHeight: 768, colorDepth: 24, pixelDepth: 24,
height: 768, width: 1024
}
global.screen = window.screen;
global.document = window.document;
global.requestAnimationFrame = function (cb) {
return setTimeout(cb, 0);
};
const config = require('../config'); //custom config as extrernal in webpack.
window.configruntime = config;
global.navigator = window.navigator;
const canvasBindings = require("canvas/lib/bindings");
global.CanvasPattern = canvasBindings.CanvasPattern;
global.CanvasGradient = canvasBindings.CanvasGradient;
// instruction for writting test:
// 1. now we only use full DOM rendering. no need to do things like : store.dispatch(actions.addFilter(;locations')),
// this is performed automatically.
// 2. no good way to spy a child component's events, such as Permalink's onClick
// 3. no good way to check a child component's state, only prop. only wrapper can get state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment