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"
});
...
}
See https://github.com/jsdom/jsdom/wiki/Don't-stuff-jsdom-globals-onto-the-Node-global. This is the exact problem you're going to run into.
@Sebmaster Thank you so much for your response. I was curious, is there any way I can make sure that the onClick
handler method is being called without actually calling it, i.e., using _fake handler_?
There probably is, but that question is more suitable for StackOverflow than here, sorry.