鉴于我的组件和测试如下,为什么我的confirmClickHandler方法在我运行测试时仍然被调用?
注意:我注意到当我将方法从胖箭头函数更改为常规函数时,它会被正确地模拟出来.我在这里错过了什么?
class CalendarConfirmation extends React.Component {
...
confirmClickHandler = (e) => {
...
}
}
Run Code Online (Sandbox Code Playgroud)
和我的测试:
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();
...
}
Run Code Online (Sandbox Code Playgroud)