Created
December 10, 2019 13:14
-
-
Save AmmarCodes/67390825bebd8f0969c32cb1ad483235 to your computer and use it in GitHub Desktop.
Mock window.confirm in Jest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('mocking window.confirm', () => { | |
// mock window.confirm | |
let windowSpy; | |
beforeEach(() => { | |
windowSpy = jest.spyOn(global, 'window', 'get'); | |
windowSpy.mockImplementation(() => ({ | |
confirm: () => {}, | |
})); | |
}); | |
afterEach(() => { | |
windowSpy.mockRestore(); | |
}); | |
it('show confirm when clicking delete card button', () => { | |
// @TODO do the action that uses window.confirm here. | |
expect(windowSpy).toHaveBeenCalled(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment