TypeError: expect.createSpy is not a function

在使用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
具體操作如下:

import jest from 'jest-mock';
const spy=fest.fn();
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章