i have written test for my api with jest . i added function that calls my api in test file as below:
import AuthManager from \"../Client/Modules/Auth/AuthMan
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();
/* ... */
})