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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Jest] Restore the Original Implementation of a Mocked JavaScript Function with jest.spyOn相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

How To Restore Rman Backups On A Different Node When The Directory Structures Are Different (Doc ID

Xfce4 panel is broken, how to restore it to the default panel without exiting current desktop?

TPO1-2 The Origin of Theater

Vue3跨域问题 [The value of the ‘Access-Control-Allow-Origin‘ header in the response must not be the..]

如何解决这个错误 jest-worker@27.0.0-next.5:The engine "node" is in compatible with this module

Microsoft - Find the K closest points to the origin in a 2D plane