📜  错误:未实现:window.alert - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:16.491000             🧑  作者: Mango

代码示例1
//How I solved this problem is actually define the window.alert method at the top of the test file as a jest spy. This should work for any window method (in my case I was actually testing window.open).

//Be sure to call mockClear() in your test, since this is a global object and it's calls will persist across tests.

window.alert = jest.fn();

test("login api resolves true", () => {
  window.alert.mockClear();
  /* ... */
})