File tree 1 file changed +28
-0
lines changed 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { render } from 'enzyme' ;
3
+ import { FieldContext } from '@/components/Field/FieldContext' ;
4
+
5
+ describe ( 'FieldContext test' , ( ) => {
6
+ it ( 'should use default values when no consumer used' , ( ) => {
7
+ const mockChangeValue = jest . fn ( ) ;
8
+ const mockChangeFocus = jest . fn ( ) ;
9
+ const container = render (
10
+ < div >
11
+ < FieldContext . Consumer >
12
+ { ( { changeValue, changeFocus } ) => {
13
+ const a = changeValue ( true ) ;
14
+ const b = changeFocus ( true ) ;
15
+
16
+ return < span > { a === undefined && b === undefined ? 'undefined' : 'defined' } </ span > ;
17
+ } }
18
+ </ FieldContext . Consumer >
19
+ </ div > ,
20
+ { context : {
21
+ changeValue : mockChangeValue ,
22
+ changeFocus : mockChangeFocus
23
+ } }
24
+ )
25
+
26
+ expect ( container . find ( 'span' ) . text ( ) ) . toBe ( 'undefined' ) ;
27
+ } ) ;
28
+ } )
You can’t perform that action at this time.
0 commit comments