在使用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