根据我的理解以及迄今为止我在各种答案中阅读的内容,并非所有生命周期方法都应该使用浅层渲染运行。尤其componentDidMount
但是,我注意到当我这样做时
beforeEach(function () {
fakeComponentDidMount = sinon.stub(Component.prototype, 'componentDidMount');
fakeComponentDidMount.callsFake(function () {});
wrapper = shallow(<Component {...props} />);
});
afterEach(function () {
fakeComponentDidMount.restore();
});
it('calls componentDidMount', function () {
expect(fakeComponentDidMount.called).to.equal(true);
});
测试通过。
那么,我在这里做错了什么还是我理解错了?