File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
packages/enzyme-test-suite/test Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -4796,6 +4796,42 @@ describe('shallow', () => {
47964796 expect ( wrapper . state ( 'foo' ) ) . to . equal ( 'onChange update' ) ;
47974797 expect ( spy ) . to . have . property ( 'callCount' , 2 ) ;
47984798 } ) ;
4799+
4800+ it ( 'should call `componentDidUpdate` when component’s `setState` is called through a bound method' , ( ) => {
4801+ const spy = sinon . spy ( ) ;
4802+ class Foo extends React . Component {
4803+ constructor ( props ) {
4804+ super ( props ) ;
4805+ this . state = {
4806+ foo : 'init' ,
4807+ } ;
4808+ this . onChange = this . onChange . bind ( this ) ;
4809+ }
4810+
4811+ componentDidUpdate ( ) {
4812+ spy ( ) ;
4813+ }
4814+
4815+ onChange ( ) {
4816+ // enzyme can't handle the update because `this` is a ReactComponent instance,
4817+ // not a ShallowWrapper instance.
4818+ this . setState ( { foo : 'onChange update' } ) ;
4819+ }
4820+
4821+ render ( ) {
4822+ return (
4823+ < div >
4824+ { this . state . foo }
4825+ < button onClick = { this . onChange } > click</ button >
4826+ </ div >
4827+ ) ;
4828+ }
4829+ }
4830+ const wrapper = shallow ( < Foo /> ) ;
4831+ wrapper . find ( 'button' ) . prop ( 'onClick' ) ( ) ;
4832+ expect ( wrapper . state ( 'foo' ) ) . to . equal ( 'onChange update' ) ;
4833+ expect ( spy ) . to . have . property ( 'callCount' , 1 ) ;
4834+ } ) ;
47994835 } ) ;
48004836
48014837 describeIf ( is ( '>= 16' ) , 'support getSnapshotBeforeUpdate' , ( ) => {
You can’t perform that action at this time.
0 commit comments