-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visitor: fix description of "ancestors" arg + test #1250
Visitor: fix description of "ancestors" arg + test #1250
Conversation
@leebyron Can you please review this PR? |
@leebyron Can you please take a look? |
enter(node, key, parent, path, ancestors) { | ||
const inArray = typeof key === 'number'; | ||
const expectedAncestors = nodesInPath.slice(0, path.length - 1); | ||
expect(ancestors).to.deep.equal(expectedAncestors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not expect(ancestors).to.deep.equal(nodesInPath);
? i.e. why is the slicing needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjmahone Because we need nodesInPath
without last element and slice(0, path.length - 1)
does exactly that it returns an array without last element.
Basically, it tests this statement:
All nodes and Arrays visited before reaching parent of this node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjmahone I rewrote this test to make it more explicit.
7fae89b
to
b446116
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for figuring out this specification, and improving the docs for it!
@mjmahone It was my pleasure. I think now |
This description is incorrect:
graphql-js/src/language/visitor.js
Lines 43 to 46 in 86d33b4
Since
ancestors
never includes parent, and it's already tested here:graphql-js/src/language/__tests__/visitor-test.js
Line 54 in 86d33b4
But I added a separate test to make it more obvious.