Skip to content

Commit c54e141

Browse files
Bring coverage to 100% 🎉 (#2358)
1 parent 4d0601b commit c54e141

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

src/language/__tests__/visitor-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ describe('Visitor', () => {
253253
);
254254
});
255255

256+
it('ignores false returned on leave', () => {
257+
const ast = parse('{ a, b, c { a, b, c } }', { noLocation: true });
258+
const returnedAST = visit(ast, {
259+
leave() {
260+
return false;
261+
},
262+
});
263+
264+
expect(returnedAST).to.deep.equal(
265+
parse('{ a, b, c { a, b, c } }', { noLocation: true }),
266+
);
267+
});
268+
256269
it('visits edited node', () => {
257270
const addedField = {
258271
kind: 'Field',

src/subscription/__tests__/subscribe-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ describe('Subscription Initialization Phase', () => {
164164
});
165165

166166
// $FlowFixMe
167+
ai.next();
167168
ai.return();
168169
});
169170

src/type/__tests__/schema-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ describe('Type System: Schema', () => {
175175

176176
expect(schema.getType('SomeInterface')).to.equal(SomeInterface);
177177
expect(schema.getType('SomeSubtype')).to.equal(SomeSubtype);
178+
179+
expect(schema.isSubType(SomeInterface, SomeSubtype)).to.equal(true);
180+
expect(schema.isPossibleType(SomeInterface, SomeSubtype)).to.equal(true);
178181
});
179182

180183
it("includes interface's thunk subtypes in the type map", () => {

src/type/schema.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ export class GraphQLSchema {
232232
abstractType: GraphQLAbstractType,
233233
possibleType: GraphQLObjectType,
234234
): boolean {
235-
/* istanbul ignore next */
236235
return this.isSubType(abstractType, possibleType);
237236
}
238237

src/validation/__tests__/validation-test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import { expect } from 'chai';
44
import { describe, it } from 'mocha';
55

6+
import { GraphQLError } from '../../error/GraphQLError';
7+
68
import { parse } from '../../language/parser';
9+
710
import { TypeInfo } from '../../utilities/TypeInfo';
11+
import { buildSchema } from '../../utilities/buildASTSchema';
812

913
import { validate } from '../validate';
1014

@@ -78,6 +82,43 @@ describe('Validate: Supports full validation', () => {
7882
'Cannot query field "isHouseTrained" on type "Dog". Did you mean "isHouseTrained"?',
7983
]);
8084
});
85+
86+
it('validates using a custom rule', () => {
87+
const schema = buildSchema(`
88+
directive @custom(arg: String) on FIELD
89+
90+
type Query {
91+
foo: String
92+
}
93+
`);
94+
95+
const doc = parse(`
96+
query {
97+
name @custom
98+
}
99+
`);
100+
101+
function customRule(context) {
102+
return {
103+
Directive(node) {
104+
const directiveDef = context.getDirective();
105+
const error = new GraphQLError(
106+
'Reporting directive: ' + String(directiveDef),
107+
node,
108+
);
109+
context.reportError(error);
110+
},
111+
};
112+
}
113+
114+
const errors = validate(schema, doc, [customRule]);
115+
expect(errors).to.deep.equal([
116+
{
117+
message: 'Reporting directive: @custom',
118+
locations: [{ line: 3, column: 14 }],
119+
},
120+
]);
121+
});
81122
});
82123

83124
describe('Validate: Limit maximum number of validation errors', () => {

0 commit comments

Comments
 (0)