Skip to content

Commit 51eda7b

Browse files
Enable Flow on validation tests + Refactoring (#1618)
1 parent 0390da9 commit 51eda7b

29 files changed

+1877
-2803
lines changed

src/validation/__tests__/ExecutableDefinitions-test.js

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
*/
99

1010
import { describe, it } from 'mocha';
11-
import { expectPassesRule, expectFailsRule } from './harness';
11+
import { expectValidationErrors } from './harness';
1212
import {
1313
ExecutableDefinitions,
1414
nonExecutableDefinitionMessage,
1515
} from '../rules/ExecutableDefinitions';
1616

17+
function expectErrors(queryStr) {
18+
return expectValidationErrors(ExecutableDefinitions, queryStr);
19+
}
20+
21+
function expectValid(queryStr) {
22+
expectErrors(queryStr).to.deep.equal([]);
23+
}
24+
1725
function nonExecutableDefinition(defName, line, column) {
1826
return {
1927
message: nonExecutableDefinitionMessage(defName),
@@ -23,22 +31,17 @@ function nonExecutableDefinition(defName, line, column) {
2331

2432
describe('Validate: Executable definitions', () => {
2533
it('with only operation', () => {
26-
expectPassesRule(
27-
ExecutableDefinitions,
28-
`
34+
expectValid(`
2935
query Foo {
3036
dog {
3137
name
3238
}
3339
}
34-
`,
35-
);
40+
`);
3641
});
3742

3843
it('with operation and fragment', () => {
39-
expectPassesRule(
40-
ExecutableDefinitions,
41-
`
44+
expectValid(`
4245
query Foo {
4346
dog {
4447
name
@@ -49,14 +52,11 @@ describe('Validate: Executable definitions', () => {
4952
fragment Frag on Dog {
5053
name
5154
}
52-
`,
53-
);
55+
`);
5456
});
5557

5658
it('with type definition', () => {
57-
expectFailsRule(
58-
ExecutableDefinitions,
59-
`
59+
expectErrors(`
6060
query Foo {
6161
dog {
6262
name
@@ -70,18 +70,14 @@ describe('Validate: Executable definitions', () => {
7070
extend type Dog {
7171
color: String
7272
}
73-
`,
74-
[
75-
nonExecutableDefinition('Cow', 8, 7),
76-
nonExecutableDefinition('Dog', 12, 7),
77-
],
78-
);
73+
`).to.deep.equal([
74+
nonExecutableDefinition('Cow', 8, 7),
75+
nonExecutableDefinition('Dog', 12, 7),
76+
]);
7977
});
8078

8179
it('with schema definition', () => {
82-
expectFailsRule(
83-
ExecutableDefinitions,
84-
`
80+
expectErrors(`
8581
schema {
8682
query: Query
8783
}
@@ -91,12 +87,10 @@ describe('Validate: Executable definitions', () => {
9187
}
9288
9389
extend schema @directive
94-
`,
95-
[
96-
nonExecutableDefinition('schema', 2, 7),
97-
nonExecutableDefinition('Query', 6, 7),
98-
nonExecutableDefinition('schema', 10, 7),
99-
],
100-
);
90+
`).to.deep.equal([
91+
nonExecutableDefinition('schema', 2, 7),
92+
nonExecutableDefinition('Query', 6, 7),
93+
nonExecutableDefinition('schema', 10, 7),
94+
]);
10195
});
10296
});

0 commit comments

Comments
 (0)