Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 5 additions & 23 deletions src/language/__tests__/visitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ function getValue(node: ASTNode) {
}

describe('Visitor', () => {
it('handles empty visitor', () => {
const ast = parse('{ a }', { noLocation: true });
expect(() => visit(ast, {})).to.not.throw();
});

it('validates path argument', () => {
const visited = [];

Expand Down Expand Up @@ -114,29 +119,6 @@ describe('Visitor', () => {
});
});

it('allows visiting only specified nodes', () => {
const ast = parse('{ a }', { noLocation: true });
const visited = [];

visit(ast, {
enter: {
Field(node) {
visited.push(['enter', node.kind]);
},
},
leave: {
Field(node) {
visited.push(['leave', node.kind]);
},
},
});

expect(visited).to.deep.equal([
['enter', 'Field'],
['leave', 'Field'],
]);
});

it('allows editing a node both on enter and on leave', () => {
const ast = parse('{ a, b, c { a, b, c } }', { noLocation: true });

Expand Down
Loading