[Jest] Restore the Original Implementation of a Mocked JavaScript Function with jest.spyOn
2021-02-02 10:18
标签:method class origin nal code ati original als span We can use ‘jest.spyOn‘, similr to ‘spyOn‘ in Jasmine. We get ‘getWinner‘ as a method. Jest has mockImplementation: We can also do the cleanup after the test: [Jest] Restore the Original Implementation of a Mocked JavaScript Function with jest.spyOn 标签:method class origin nal code ati original als span 原文地址:https://www.cnblogs.com/Answer1215/p/12808917.htmljest.spyOn(utils, ‘getWinner‘)
// from
utils.getWinner = jest.fn((p1, p2) => p2)
// to
utils.getWinner.mockImplementation((p1, p2) => p2)
// cleanup
utils.getWinner.mockRestore()
文章标题:[Jest] Restore the Original Implementation of a Mocked JavaScript Function with jest.spyOn
文章链接:http://soscw.com/index.php/essay/49929.html