TypeError: expect.createSpy is not a function

迈不过友情╰ 2022-05-25 12:22 157阅读 0赞

在使用Expect进行测试过程中,遇到TypeError: expect.createSpy is not a function 该问题,那是因为:

This package has been donated to Jest. This means that all future development of expect v21+ will take place at facebook/jest.

因此,如果你使用的是21+版本,应该使用fest.fn代替expect.createSpy
具体操作如下:

  1. import jest from 'jest-mock';
  2. const spy=fest.fn();
  3. spy();

参考:https://stackoverflow.com/questions/46752389/typeerror-expect-createspy-is-not-a-function
https://stackoverflow.com/questions/46086970/getting-typeerror-jest-fn-is-not-a-function

发表评论

表情:
评论列表 (有 0 条评论,157人围观)

还没有评论,来说两句吧...

相关阅读