@@ -36,3 +36,42 @@ describe('context expect', () => {
3636 expect ( localExpect . getState ( ) . snapshotState ) . toBeDefined ( )
3737 } )
3838} )
39+
40+ describe ( 'custom matcher are inherited by local context' , ( ) => {
41+ expect . extend ( {
42+ toEqual_testCustom ( received , expected ) {
43+ return {
44+ pass : received === expected ,
45+ message : ( ) => `test` ,
46+ }
47+ } ,
48+ } )
49+
50+ it ( 'basic' , ( { expect : localExpect } ) => {
51+ // as assertion
52+ expect ( expect ( 'test' ) ) . toHaveProperty ( 'toEqual_testCustom' )
53+ expect ( expect . soft ( 'test' ) ) . toHaveProperty ( 'toEqual_testCustom' )
54+ expect ( localExpect ( 'test' ) ) . toHaveProperty ( 'toEqual_testCustom' )
55+ expect ( localExpect . soft ( 'test' ) ) . toHaveProperty ( 'toEqual_testCustom' )
56+
57+ // as asymmetric matcher
58+ expect ( expect ) . toHaveProperty ( 'toEqual_testCustom' )
59+ expect ( expect . not ) . toHaveProperty ( 'toEqual_testCustom' )
60+ expect ( localExpect ) . toHaveProperty ( 'toEqual_testCustom' )
61+ expect ( localExpect . not ) . toHaveProperty ( 'toEqual_testCustom' ) ;
62+
63+ ( expect ( 0 ) as any ) . toEqual_testCustom ( 0 ) ;
64+ ( expect ( 0 ) as any ) . not . toEqual_testCustom ( 1 ) ;
65+ ( localExpect ( 0 ) as any ) . toEqual_testCustom ( 0 ) ;
66+ ( localExpect ( 0 ) as any ) . not . toEqual_testCustom ( 1 )
67+
68+ expect ( 0 ) . toEqual ( ( expect as any ) . toEqual_testCustom ( 0 ) )
69+ localExpect ( 0 ) . toEqual ( ( localExpect as any ) . toEqual_testCustom ( 0 ) )
70+ expect ( 0 ) . toEqual ( ( expect . not as any ) . toEqual_testCustom ( 1 ) )
71+ localExpect ( 0 ) . toEqual ( ( localExpect . not as any ) . toEqual_testCustom ( 1 ) )
72+
73+ // asymmetric matcher function is identical
74+ expect ( ( expect as any ) . toEqual_testCustom ) . toBe ( ( localExpect as any ) . toEqual_testCustom )
75+ expect ( ( expect . not as any ) . toEqual_testCustom ) . toBe ( ( localExpect . not as any ) . toEqual_testCustom )
76+ } )
77+ } )
0 commit comments