Skip to content

Commit a1dd00b

Browse files
committed
update after simulatError
1 parent ac35c19 commit a1dd00b

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

packages/enzyme-test-suite/test/ReactWrapper-spec.jsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,13 +5033,19 @@ describeWithDOM('mount', () => {
50335033
class ErrorBoundary extends React.Component {
50345034
constructor(...args) {
50355035
super(...args);
5036-
this.state = { throws: false };
5036+
this.state = {
5037+
throws: false,
5038+
didThrow: false,
5039+
};
50375040
}
50385041

50395042
componentDidCatch(error, info) {
50405043
const { spy } = this.props;
50415044
spy(error, info);
5042-
this.setState({ throws: false });
5045+
this.setState({
5046+
throws: false,
5047+
didThrow: true,
5048+
});
50435049
}
50445050

50455051
render() {
@@ -5049,6 +5055,11 @@ describeWithDOM('mount', () => {
50495055
<MaybeFragment>
50505056
<span>
50515057
<Thrower throws={throws} />
5058+
<div>
5059+
{this.state.didThrow?
5060+
'HasThrown' : 'HasNotThrown'
5061+
}
5062+
</div>
50525063
</span>
50535064
</MaybeFragment>
50545065
</div>
@@ -5096,6 +5107,18 @@ describeWithDOM('mount', () => {
50965107
});
50975108
});
50985109

5110+
it('rerenders on a simulated error', () => {
5111+
const wrapper = mount(<ErrorBoundary spy={sinon.stub()} />);
5112+
5113+
expect(wrapper.find({ children: 'HasThrown' })).to.have.lengthOf(0);
5114+
expect(wrapper.find({ children: 'HasNotThrown' })).to.have.lengthOf(1);
5115+
5116+
expect(() => wrapper.find(Thrower).simulateError(errorToThrow)).not.to.throw();
5117+
5118+
expect(wrapper.find({ children: 'HasThrown' })).to.have.lengthOf(1);
5119+
expect(wrapper.find({ children: 'HasNotThrown' })).to.have.lengthOf(0);
5120+
});
5121+
50995122
it('catches errors during render', () => {
51005123
const spy = sinon.spy();
51015124
const wrapper = mount(<ErrorBoundary spy={spy} />);

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5067,13 +5067,19 @@ describe('shallow', () => {
50675067
class ErrorBoundary extends React.Component {
50685068
constructor(...args) {
50695069
super(...args);
5070-
this.state = { throws: false };
5070+
this.state = {
5071+
throws: false,
5072+
didThrow: false,
5073+
};
50715074
}
50725075

50735076
componentDidCatch(error, info) {
50745077
const { spy } = this.props;
50755078
spy(error, info);
5076-
this.setState({ throws: false });
5079+
this.setState({
5080+
throws: false,
5081+
didThrow: true,
5082+
});
50775083
}
50785084

50795085
render() {
@@ -5083,6 +5089,11 @@ describe('shallow', () => {
50835089
<MaybeFragment>
50845090
<span>
50855091
<Thrower throws={throws} />
5092+
<div>
5093+
{this.state.didThrow?
5094+
'HasThrown' : 'HasNotThrown'
5095+
}
5096+
</div>
50865097
</span>
50875098
</MaybeFragment>
50885099
</div>
@@ -5124,6 +5135,18 @@ describe('shallow', () => {
51245135
});
51255136
});
51265137

5138+
it('rerenders on a simulated error', () => {
5139+
const wrapper = shallow(<ErrorBoundary spy={sinon.stub()} />);
5140+
5141+
expect(wrapper.find({ children: 'HasThrown' })).to.have.lengthOf(0);
5142+
expect(wrapper.find({ children: 'HasNotThrown' })).to.have.lengthOf(1);
5143+
5144+
expect(() => wrapper.find(Thrower).simulateError(errorToThrow)).not.to.throw();
5145+
5146+
expect(wrapper.find({ children: 'HasThrown' })).to.have.lengthOf(1);
5147+
expect(wrapper.find({ children: 'HasNotThrown' })).to.have.lengthOf(0);
5148+
});
5149+
51275150
it('does not catch errors during shallow render', () => {
51285151
const spy = sinon.spy();
51295152
const wrapper = shallow(<ErrorBoundary spy={spy} />);
@@ -5141,6 +5164,9 @@ describe('shallow', () => {
51415164
expect(() => thrower.dive()).to.throw(errorToThrow);
51425165

51435166
expect(spy).to.have.property('callCount', 0);
5167+
5168+
expect(wrapper.find({ children: 'HasThrown' })).to.have.lengthOf(0);
5169+
expect(wrapper.find({ children: 'HasNotThrown' })).to.have.lengthOf(1);
51445170
});
51455171
});
51465172
});

packages/enzyme/src/ReactWrapper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ class ReactWrapper {
643643
const nodeHierarchy = [thisNode].concat(nodeParents(this, thisNode));
644644
renderer.simulateError(nodeHierarchy, rootNode, error);
645645

646+
this[ROOT].update();
646647
return this;
647648
});
648649
}

0 commit comments

Comments
 (0)