@@ -3045,6 +3045,63 @@ describeWithDOM('mount', () => {
30453045
30463046 expect ( mount ( < Comp /> ) . debug ( ) ) . to . equal ( '<Comp />' ) ;
30473047 } ) ;
3048+
3049+ describe ( 'child components' , ( ) => {
3050+ class Child extends React . Component {
3051+ constructor ( ...args ) {
3052+ super ( ...args ) ;
3053+ this . state = { state : 'a' } ;
3054+ }
3055+
3056+ render ( ) {
3057+ const { prop } = this . props ;
3058+ const { state } = this . state ;
3059+ return (
3060+ < div >
3061+ { prop } - { state }
3062+ </ div >
3063+ ) ;
3064+ }
3065+ }
3066+
3067+ class Parent extends React . Component {
3068+ constructor ( ...args ) {
3069+ super ( ...args ) ;
3070+ this . state = { childProp : 1 } ;
3071+ }
3072+
3073+ render ( ) {
3074+ const { childProp } = this . state ;
3075+ return < Child prop = { childProp } /> ;
3076+ }
3077+ }
3078+
3079+ it ( 'sets the state of the parent' , ( ) => {
3080+ const wrapper = mount ( < Parent /> ) ;
3081+
3082+ expect ( wrapper . text ( ) . trim ( ) ) . to . eql ( '1 - a' ) ;
3083+
3084+ return new Promise ( ( resolve ) => {
3085+ wrapper . setState ( { childProp : 2 } , ( ) => {
3086+ expect ( wrapper . text ( ) . trim ( ) ) . to . eql ( '2 - a' ) ;
3087+ resolve ( ) ;
3088+ } ) ;
3089+ } ) ;
3090+ } ) ;
3091+
3092+ it ( 'sets the state of the child' , ( ) => {
3093+ const wrapper = mount ( < Parent /> ) ;
3094+
3095+ expect ( wrapper . text ( ) . trim ( ) ) . to . eql ( '1 - a' ) ;
3096+
3097+ return new Promise ( ( resolve ) => {
3098+ wrapper . find ( Child ) . setState ( { state : 'b' } , ( ) => {
3099+ expect ( wrapper . text ( ) . trim ( ) ) . to . eql ( '1 - b' ) ;
3100+ resolve ( ) ;
3101+ } ) ;
3102+ } ) ;
3103+ } ) ;
3104+ } ) ;
30483105 } ) ;
30493106
30503107 describe ( '.is(selector)' , ( ) => {
@@ -3597,6 +3654,49 @@ describeWithDOM('mount', () => {
35973654 expect ( ( ) => wrapper . state ( ) ) . to . throw ( Error , 'ReactWrapper::state() can only be called on class components' ) ;
35983655 } ) ;
35993656 } ) ;
3657+
3658+ describe ( 'child components' , ( ) => {
3659+ class Child extends React . Component {
3660+ constructor ( ...args ) {
3661+ super ( ...args ) ;
3662+ this . state = { state : 'a' } ;
3663+ }
3664+
3665+ render ( ) {
3666+ const { prop } = this . props ;
3667+ const { state } = this . state ;
3668+ return (
3669+ < div >
3670+ { prop } - { state }
3671+ </ div >
3672+ ) ;
3673+ }
3674+ }
3675+
3676+ class Parent extends React . Component {
3677+ constructor ( ...args ) {
3678+ super ( ...args ) ;
3679+ this . state = { childProp : 1 } ;
3680+ }
3681+
3682+ render ( ) {
3683+ const { childProp } = this . state ;
3684+ return < Child prop = { childProp } /> ;
3685+ }
3686+ }
3687+
3688+ it ( 'gets the state of the parent' , ( ) => {
3689+ const wrapper = mount ( < Parent /> ) ;
3690+
3691+ expect ( wrapper . state ( ) ) . to . eql ( { childProp : 1 } ) ;
3692+ } ) ;
3693+
3694+ it ( 'gets the state of the child' , ( ) => {
3695+ const wrapper = mount ( < Parent /> ) ;
3696+
3697+ expect ( wrapper . find ( Child ) . state ( ) ) . to . eql ( { state : 'a' } ) ;
3698+ } ) ;
3699+ } ) ;
36003700 } ) ;
36013701
36023702 describe ( '.children([selector])' , ( ) => {
0 commit comments