@@ -17,6 +17,35 @@ import { testSchema } from '../../validation/__tests__/harness';
17
17
import { getNamedType , isCompositeType } from '../../type' ;
18
18
19
19
describe ( 'Visitor' , ( ) => {
20
+ it ( 'check path argument' , ( ) => {
21
+ const visited = [ ] ;
22
+
23
+ const ast = parse ( '{ a }' ) ;
24
+ visit ( ast , {
25
+ enter ( node , key , parent , path ) {
26
+ visited . push ( [ 'enter' , path . slice ( ) ] ) ;
27
+ } ,
28
+
29
+ leave ( node , key , parent , path ) {
30
+ visited . push ( [ 'leave' , path . slice ( ) ] ) ;
31
+ } ,
32
+ } ) ;
33
+
34
+ console . log ( JSON . stringify ( visited , null , 2 ) ) ;
35
+ expect ( visited ) . to . deep . equal ( [
36
+ [ 'enter' , [ ] ] ,
37
+ [ 'enter' , [ 'definitions' , 0 ] ] ,
38
+ [ 'enter' , [ 'definitions' , 0 , 'selectionSet' ] ] ,
39
+ [ 'enter' , [ 'definitions' , 0 , 'selectionSet' , 'selections' , 0 ] ] ,
40
+ [ 'enter' , [ 'definitions' , 0 , 'selectionSet' , 'selections' , 0 , 'name' ] ] ,
41
+ [ 'leave' , [ 'definitions' , 0 , 'selectionSet' , 'selections' , 0 ] ] ,
42
+ [ 'leave' , [ 'definitions' , 0 , 'selectionSet' , 'selections' ] ] ,
43
+ [ 'leave' , [ 'definitions' , 0 ] ] ,
44
+ [ 'leave' , [ 'definitions' ] ] ,
45
+ [ 'leave' , [ ] ] ,
46
+ ] ) ;
47
+ } ) ;
48
+
20
49
it ( 'allows editing a node both on enter and on leave' , ( ) => {
21
50
const ast = parse ( '{ a, b, c { a, b, c } }' , { noLocation : true } ) ;
22
51
0 commit comments