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);
});
});
const jsdom = new JSDOM("<!DOCTYPE HTML><html><body></body></html>");
global.window = jsdom.window;
global.document = jsdom.window.document;
global.navigator = {
userAgent: "node.js"
};
...
...
onClick() {
const blob = new Blob([ this.props.code ], {
type: "text/plain;charset=ascii"
});
...
}
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é.