我的测试用例是这样的:
describe('Personal Profile', () => {
it('renders', () => {
const wrapper = mount(
<PersonalProfile store={store}/>
);
const spy = jest.spyOn(wrapper.instance(), 'handleChangetype')
wrapper.update();
wrapper.find(Typeahead).at(2).simulate('change');
console.log(wrapper.find(Typeahead).at(2).simulate('change').debug())
expect(spy).toHaveBeenCalled();
});
});
在运行测试用例时出现上述错误。
在我的js文件中,虽然我遇到此错误,但我没有使用箭头函数并在构造函数中绑定了方法。
有人可以帮忙吗?
答案 0 :(得分:1)
我能够弄清楚。问题是我使用了redux存储,并试图在connect组件中找到该方法。因此,我需要做的是在包装器上调用.first()。shallow()以获得所需的组件。
const wrapper = shallow(
<PersonalProfile store={store}/>
).first().shallow().first().shallow();
这样做是因为我有两个HOC,所以要获得所需的分量,我必须将先前返回的第一个分量变浅两次。