【发布时间】:2017-09-28 03:32:56
【问题描述】:
我有一个使用来自jest 的spyOn 方法的单元测试。
import React from 'react';
import expect from 'jest-matchers';
import PointsAwardingPage from '../PointsAwardingPage';
import PointsAwardingForm from '../children/PointsAwardingForm';
import { shallow } from 'enzyme';
it("should call change method in form", () => {
// given
spyOn(PointsAwardingPage.prototype, 'change').and.callThrough();
const form = shallow(<PointsAwardingPage />).find('PointsAwardingForm');
// when
form.props().onChange();
// then
expect(PointsAwardingPage.prototype.change).toHaveBeenCalled();
});
一切正常。但是,我看到以下关于spyOn 函数调用的eslint 错误消息。
spyOn is not defined (no-undef).
我可以使用哪个import 语句来消除此错误?
【问题讨论】:
标签: javascript unit-testing jestjs eslint