@@ -37,6 +37,38 @@ describe('PureComponent', () => {
3737 expect ( spy ) . to . be . calledWithMatch ( expected , expected ) ;
3838 } ) ;
3939
40+ it ( 'should pass context in constructor' , ( ) => {
41+ let instance ;
42+ // Not initializing state matches React behavior: https://codesandbox.io/s/rml19v8o2q
43+ class Foo extends React . PureComponent {
44+ constructor ( props , context ) {
45+ super ( props , context ) ;
46+ expect ( this . props ) . to . equal ( props ) ;
47+ expect ( this . state ) . to . deep . equal ( undefined ) ;
48+ expect ( this . context ) . to . equal ( context ) ;
49+
50+ instance = this ;
51+ }
52+ render ( props ) {
53+ return < div { ...props } > Hello</ div > ;
54+ }
55+ }
56+
57+ sinon . spy ( Foo . prototype , 'render' ) ;
58+
59+ const PROPS = { foo : 'bar' } ;
60+ React . render ( < Foo { ...PROPS } /> , scratch ) ;
61+
62+ expect ( Foo . prototype . render )
63+ . to . have . been . calledOnce . and . to . have . been . calledWithMatch ( PROPS , { } , { } )
64+ . and . to . have . returned ( sinon . match ( { type : 'div' , props : PROPS } ) ) ;
65+ expect ( instance . props ) . to . deep . equal ( PROPS ) ;
66+ expect ( instance . state ) . to . deep . equal ( { } ) ;
67+ expect ( instance . context ) . to . deep . equal ( { } ) ;
68+
69+ expect ( scratch . innerHTML ) . to . equal ( '<div foo="bar">Hello</div>' ) ;
70+ } ) ;
71+
4072 it ( 'should ignore the __source variable' , ( ) => {
4173 const pureSpy = sinon . spy ( ) ;
4274 const appSpy = sinon . spy ( ) ;
0 commit comments