jest enzyme TypeError: Cannot read property 'fn' of undefined
jest enzyme TypeError: Cannot read property 'fn' of undefined
我正在写测试,下面是我的测试用例。
import { mount, jest } from 'enzyme';
it('should submit job post form on save button click', () => {
const onPostJobSubmit = jest.fn(); // Here is the error.
const instance = wrapper.instance();
wrapper.find('button').simulate('click');
expect(onPostJobSubmit).toHaveBeenCalled();
});
当我 运行 测试时,出现以下错误。
TypeError: Cannot read property 'fn' of undefined
61 |
62 | it('should submit job post form on save button click', () => {
> 63 | const onPostJobSubmit = jest.fn();
这有什么问题,我该如何解决?
来自doc:
The jest
object is automatically in scope within every test file. The methods in the jest object help create mocks and let you control Jest's overall behavior. It can also be imported explicitly by via import {jest} from '@jest/globals'
.
我正在写测试,下面是我的测试用例。
import { mount, jest } from 'enzyme';
it('should submit job post form on save button click', () => {
const onPostJobSubmit = jest.fn(); // Here is the error.
const instance = wrapper.instance();
wrapper.find('button').simulate('click');
expect(onPostJobSubmit).toHaveBeenCalled();
});
当我 运行 测试时,出现以下错误。
TypeError: Cannot read property 'fn' of undefined
61 |
62 | it('should submit job post form on save button click', () => {
> 63 | const onPostJobSubmit = jest.fn();
这有什么问题,我该如何解决?
来自doc:
The
jest
object is automatically in scope within every test file. The methods in the jest object help create mocks and let you control Jest's overall behavior. It can also be imported explicitly by viaimport {jest} from '@jest/globals'
.