File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
enzyme-adapter-react-16/src Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -690,7 +690,13 @@ class ReactSixteenAdapter extends EnzymeAdapter {
690
690
renderedEl = transformSuspense ( renderedEl , renderedEl , { suspenseFallback } ) ;
691
691
const { type : Component } = renderedEl ;
692
692
693
- const context = getMaskedContext ( Component . contextTypes , unmaskedContext ) ;
693
+ let context ;
694
+ if ( Component . contextType ) {
695
+ const Provider = adapter . getProviderFromConsumer ( Component . contextType ) ;
696
+ context = providerValues . has ( Provider ) ? providerValues . get ( Provider ) : getProviderDefaultValue ( Provider ) ;
697
+ } else {
698
+ context = getMaskedContext ( Component . contextTypes , unmaskedContext ) ;
699
+ }
694
700
695
701
if ( isMemo ( el . type ) ) {
696
702
const { type : InnerComp , compare } = el . type ;
Original file line number Diff line number Diff line change @@ -666,6 +666,34 @@ describe('shallow', () => {
666
666
expect ( consumer . text ( ) ) . to . equal ( 'foo' ) ;
667
667
} ) ;
668
668
} ) ;
669
+
670
+ describe ( 'shallow() on Provider and Consumer through .contextType' , ( ) => {
671
+
672
+ const { Provider } = React . createContext ( 'howdy!' ) ;
673
+
674
+ class OuterComponent extends React . Component {
675
+ render ( ) {
676
+ return (
677
+ < Provider value = "foo" > < InnerComponent /> </ Provider >
678
+ ) ;
679
+ }
680
+ }
681
+
682
+ class InnerComponent extends React . Component {
683
+ render ( ) {
684
+ return this . context ;
685
+ }
686
+ }
687
+
688
+ InnerComponent . contextType = Provider ;
689
+
690
+ it ( 'works on a Provider' , ( ) => {
691
+ const wrapper = shallow ( < OuterComponent /> ) ;
692
+ const provides = wrapper . find ( Provider ) . dive ( ) ;
693
+ const provider = provides . find ( InnerComponent ) . shallow ( ) ;
694
+ expect ( provider . text ( ) ) . to . equal ( 'foo' ) ;
695
+ } ) ;
696
+ } ) ;
669
697
} ) ;
670
698
671
699
describeIf ( is ( '> 0.13' ) , 'stateless function components (SFCs)' , ( ) => {
You can’t perform that action at this time.
0 commit comments