Skip to content

Commit

Permalink
Tests to demostrate problem
Browse files Browse the repository at this point in the history
  • Loading branch information
dminkovsky committed Feb 20, 2016
1 parent 75e7be0 commit f95bc48
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/language/__tests__/visitor.js
Expand Up @@ -20,6 +20,63 @@ import { getNamedType, isCompositeType } from '../../type';


describe('Visitor', () => {

it('allows editing a node both on enter and on leave', () => {

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

let selectionSet;

const editedAst = visit(ast, {
OperationDefinition: {
enter(node) {
selectionSet = node.selectionSet;
return {
...node,
selectionSet: {
kind: 'SelectionSet',
selections: []
},
};
},
leave(node) {
return {
...node,
selectionSet,
};
}
}
});

expect(editedAst).to.deep.equal(ast);
});

it('allows editing the root node on enter and on leave', () => {

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

const { definitions } = ast;

const editedAst = visit(ast, {
Document: {
enter(node) {
return {
...node,
definitions: []
};
},
leave(node) {
return {
...node,
definitions,
};
}
}
});

expect(editedAst).to.deep.equal(ast);
});

it('allows for editing on enter', () => {

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

0 comments on commit f95bc48

Please sign in to comment.