In my package.json I have jest 24.1.0 yet my test tell me
"TypeError: _jest.default.spyOn is not a function"
The Jest docs say spyOn is a method I can use but somehow it is not available to me. What am I doing wrong?
https://jestjs.io/docs/en/jest-object#jestspyonobject-methodname
here is my test...
import React from 'react';
import jest from 'jest';
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({adapter: new Adapter()});
import NavLink from '../Tabs/NavLink';
describe('NavLink', () => {
it('handles onClick prop', () => {
const onClick = jest.fn();
const e = jest.spyOn('e', ['preventDefault']);
const wrapper = shallow(
<NavLink onClick={onClick} />
);
wrapper.find('a').simulate('click', e);
expect(onClick).toHaveBeenCalled();
expect(e.preventDefault).not.toHaveBeenCalled();
});
}
答案 0 :(得分:0)
只需删除此行:
import jest from 'jest';
Jest
查找并运行您的测试,因此jest
already exists in the scope of your test会在运行时进行测试。无需导入它,这样做会导致您看到的错误。