Gewusst wie: hinzufügen <canvas> Unterstützung für meine Prüfungen im Scherz?

In meinem Scherz unit-test-ich bin rendering-Komponente mit ColorPicker. Die ColorPicker - Komponente erstellt ein canvas-Objekt und 2d-Kontext aber zurück 'undefined' die wirft einen Fehler "Cannot set property 'fillStyle' of undefined"

if (typeof document == 'undefined') return null; //Dont Render On Server
var canvas = document.createElement('canvas'); 
canvas.width = canvas.height = size * 2;
var ctx = canvas.getContext('2d'); //returns 'undefined'
ctx.fillStyle = c1; //"Cannot set property 'fillStyle' of undefined"

Ich habe Schwierigkeiten, herauszufinden, warum ich nicht bekommen kann einen 2d-Kontext. Vielleicht gibt es ja auch ein Problem mit meine test config?

"jest": {
  "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
  "unmockedModulePathPatterns": [
    "<rootDir>/node_modules/react",
    "<rootDir>/node_modules/react-dom",
    "<rootDir>/node_modules/react-addons-test-utils",
    "<rootDir>/node_modules/react-tools"
  ],
  "moduleFileExtensions": [
    "jsx",
    "js",
    "json",
    "es6"
  ],
  "testFileExtensions": [
    "jsx"
  ],
  "collectCoverage": true
}
InformationsquelleAutor Adgezaza | 2015-10-21
Schreibe einen Kommentar