Jsdom: ReferenceError : le blob n'est pas défini

Créé le 16 avr. 2018  ·  3Commentaires  ·  Source: jsdom/jsdom

Informations de base:

  • Version de Node.js : 6.12.3
  • version jsdom : 11.6.2

Cas de reproduction minimale

  • Test
import { spy } from "sinon";
import SaveBtn from "../../../app/component/SaveBtn";

const onClickSpy = spy(SaveBtn.prototype, "onClick");

const SaveBtnTest = describe("Testing Submit Button component", function () {
    const SaveBtnElement = renderComponent(SaveBtn);
    ...
    it("should call the submit handler when clicked", function () {
        SaveBtnElement.find("button").simulate("click");
        assert(onClickSpy.calledOnce, true);
    });
});
  • Configuration
const jsdom      = new JSDOM("<!DOCTYPE HTML><html><body></body></html>");
global.window    = jsdom.window;
global.document  = jsdom.window.document;
global.navigator = {
    userAgent: "node.js"
};
...
  • Composant
...
onClick() {
    const blob = new Blob([ this.props.code ], {
        type: "text/plain;charset=ascii"
    });
    ...
}

Tous les 3 commentaires

Voir https://github.com/jsdom/jsdom/wiki/Don 't-stuff-jsdom-globals-onto-the-Node-global. C'est exactement le problème que vous allez rencontrer.

@Sebmaster Merci beaucoup pour votre réponse. J'étais curieux, y a-t-il un moyen de m'assurer que la méthode du gestionnaire onClick est appelée sans l'appeler réellement, c'est-à-dire en utilisant _fake handler_ ?

Il y en a probablement, mais cette question est plus appropriée pour StackOverflow qu'ici, désolé.

Cette page vous a été utile?
0 / 5 - 0 notes