码迷,mamicode.com
首页 > 编程语言 > 详细

[Jest] Restore the Original Implementation of a Mocked JavaScript Function with jest.spyOn

时间:2020-04-30 15:55:04      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:method   class   origin   nal   code   ati   original   als   span   

We can use ‘jest.spyOn‘, similr to ‘spyOn‘ in Jasmine.

jest.spyOn(utils, getWinner)

We get ‘getWinner‘ as a method.

 

Jest has mockImplementation:

// from

utils.getWinner = jest.fn((p1, p2) => p2)

// to

utils.getWinner.mockImplementation((p1, p2) => p2)

 

We can also do the cleanup after the test:

  // cleanup
  utils.getWinner.mockRestore()

 

[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.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!