Skip to content

Commit

Permalink
Test that SchemaDirectiveVisitor.getLocations works.
Browse files Browse the repository at this point in the history
This was a good test, since it exposed a bug (also fixed in this commit).
  • Loading branch information
benjamn committed Mar 14, 2018
1 parent 00786cb commit 2b9401c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ export class SchemaDirectiveVisitor {
public static getLocations() {
if (this.locations === null) {
this.locations = [];
for (let key in this) {
for (let key in this.prototype) {
if (hasOwn.call(methodToLocationMap, key)) {
const method = this[key];
const method = this.prototype[key];
if (typeof method === 'function' &&
! visitMethodStubSet.has(method)) {
this.locations.push(methodToLocationMap[key]);
Expand Down
26 changes: 26 additions & 0 deletions src/test/testDirectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,32 @@ describe('@directives', () => {
});
});

it('can use visitor methods to generate locations implicitly', () => {
assert.deepEqual((class extends SchemaDirectiveVisitor {
/* tslint:disable:no-empty */
public visitSchema() {}
public visitScalar() {}
public visitObject() {}
public visitFieldDefinition() {}
public visitArgumentDefinition() {}
public visitEnum() {}
public visitEnumValue() {}
public visitInputObject() {}
public visitInputFieldDefinition() {}
/* tslint:enable:no-empty */
}).getLocations().sort(), [
DirectiveLocation.ARGUMENT_DEFINITION,
DirectiveLocation.ENUM,
DirectiveLocation.ENUM_VALUE,
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.INPUT_FIELD_DEFINITION,
DirectiveLocation.INPUT_OBJECT,
DirectiveLocation.OBJECT,
DirectiveLocation.SCALAR,
DirectiveLocation.SCHEMA,
]);
});

it('can handle all kinds of undeclared arguments', () => {
const schemaText = `
enum SpineEnum {
Expand Down

0 comments on commit 2b9401c

Please sign in to comment.