Skip to content

Commit f95bc48

Browse files
committed
Tests to demostrate problem
1 parent 75e7be0 commit f95bc48

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/language/__tests__/visitor.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,63 @@ import { getNamedType, isCompositeType } from '../../type';
2020

2121

2222
describe('Visitor', () => {
23+
24+
it('allows editing a node both on enter and on leave', () => {
25+
26+
const ast = parse('{ a, b, c { a, b, c } }', { noLocation: true });
27+
28+
let selectionSet;
29+
30+
const editedAst = visit(ast, {
31+
OperationDefinition: {
32+
enter(node) {
33+
selectionSet = node.selectionSet;
34+
return {
35+
...node,
36+
selectionSet: {
37+
kind: 'SelectionSet',
38+
selections: []
39+
},
40+
};
41+
},
42+
leave(node) {
43+
return {
44+
...node,
45+
selectionSet,
46+
};
47+
}
48+
}
49+
});
50+
51+
expect(editedAst).to.deep.equal(ast);
52+
});
53+
54+
it('allows editing the root node on enter and on leave', () => {
55+
56+
const ast = parse('{ a, b, c { a, b, c } }', { noLocation: true });
57+
58+
const { definitions } = ast;
59+
60+
const editedAst = visit(ast, {
61+
Document: {
62+
enter(node) {
63+
return {
64+
...node,
65+
definitions: []
66+
};
67+
},
68+
leave(node) {
69+
return {
70+
...node,
71+
definitions,
72+
};
73+
}
74+
}
75+
});
76+
77+
expect(editedAst).to.deep.equal(ast);
78+
});
79+
2380
it('allows for editing on enter', () => {
2481

2582
const ast = parse('{ a, b, c { a, b, c } }', { noLocation: true });

0 commit comments

Comments
 (0)