鉴于下面的组件和测试,为什么我的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();
...
}