@@ -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,50 @@ 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 = { a : 'a' } ;
3663+ }
3664+
3665+ render ( ) {
3666+ const { _ } = this . props ;
3667+ const { a } = this . state ;
3668+ return (
3669+ < div >
3670+ { _ }
3671+ { a }
3672+ </ div >
3673+ ) ;
3674+ }
3675+ }
3676+
3677+ class Parent extends React . Component {
3678+ constructor ( ...args ) {
3679+ super ( ...args ) ;
3680+ this . state = { _ : 1 } ;
3681+ }
3682+
3683+ render ( ) {
3684+ const { _ } = this . state ;
3685+ return < Child _ = { _ } /> ;
3686+ }
3687+ }
3688+
3689+ it ( 'gets the state of the parent' , ( ) => {
3690+ const wrapper = mount ( < Parent /> ) ;
3691+
3692+ expect ( wrapper . state ( ) ) . to . eql ( { _ : 1 } ) ;
3693+ } ) ;
3694+
3695+ it ( 'gets the state of the child' , ( ) => {
3696+ const wrapper = mount ( < Parent /> ) ;
3697+
3698+ expect ( wrapper . find ( Child ) . state ( ) ) . to . eql ( { a : 'a' } ) ;
3699+ } ) ;
3700+ } ) ;
36003701 } ) ;
36013702
36023703 describe ( '.children([selector])' , ( ) => {
0 commit comments