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"
});
...
}
@Sebmaster 非常感谢您的回复。 我很好奇,有什么方法可以确保在没有实际调用它的情况下调用onClick
处理程序方法,即使用_fake handler_?
可能有,但是这个问题比这里更适合 StackOverflow,抱歉。