【发布时间】:2018-01-12 15:36:40
【问题描述】:
鉴于我的组件和下面的测试,为什么我的 confirmClickHandler 方法在我运行测试时仍然被调用?
注意:我注意到当我将方法从一个粗箭头函数更改为一个普通函数时,它会被正确地模拟出来。我在这里错过了什么?
class CalendarConfirmation extends React.Component {
...
confirmClickHandler = (e) => {
...
}
}
和我的测试:
import React from 'react';
import {mount} from 'enzyme';
import CalendarConfirmation from '../components/CalendarConfirmation';
describe('Test CalendarConfirmation', () => {
let calendarConfirmation;
calendarConfirmation = mount (<CalendarConfirmation />);
calendarConfirmation.instance().confirmClickHandler = jest.fn();
...
}
【问题讨论】:
-
嗨,如果你这样做了,我很想知道你是怎么想出来的。
标签: javascript reactjs jestjs babel-jest