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"
});
...
}
https://github.com/jsdom/jsdom/wiki/Don 't-stuff-jsdom-globals-onto-the-Node-global์ ์ฐธ์กฐ
@Sebmaster ๋ต๋ณ ๊ฐ์ฌํฉ๋๋ค. ๋๋ onClick
ํธ๋ค๋ฌ ๋ฉ์๋๋ฅผ ์ค์ ๋ก ํธ์ถํ์ง ์๊ณ , ์ฆ _fake ํธ๋ค๋ฌ_๋ฅผ ์ฌ์ฉํ์ฌ ํธ์ถ๋๊ณ ์๋์ง ํ์ธํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์๋์ง ๊ถ๊ธํฉ๋๋ค.
์์ ์๋ ์์ง๋ง ๊ทธ ์ง๋ฌธ์ ์ฌ๊ธฐ๋ณด๋ค StackOverflow์ ๋ ์ ํฉํฉ๋๋ค. ์ฃ์กํฉ๋๋ค.