8
8
*/
9
9
10
10
import { describe , it } from 'mocha' ;
11
- import { expectPassesRule , expectFailsRule } from './harness' ;
11
+ import { expectValidationErrors } from './harness' ;
12
12
import {
13
13
ExecutableDefinitions ,
14
14
nonExecutableDefinitionMessage ,
15
15
} from '../rules/ExecutableDefinitions' ;
16
16
17
+ function expectErrors ( queryStr ) {
18
+ return expectValidationErrors ( ExecutableDefinitions , queryStr ) ;
19
+ }
20
+
21
+ function expectValid ( queryStr ) {
22
+ expectErrors ( queryStr ) . to . deep . equal ( [ ] ) ;
23
+ }
24
+
17
25
function nonExecutableDefinition ( defName , line , column ) {
18
26
return {
19
27
message : nonExecutableDefinitionMessage ( defName ) ,
@@ -23,22 +31,17 @@ function nonExecutableDefinition(defName, line, column) {
23
31
24
32
describe ( 'Validate: Executable definitions' , ( ) => {
25
33
it ( 'with only operation' , ( ) => {
26
- expectPassesRule (
27
- ExecutableDefinitions ,
28
- `
34
+ expectValid ( `
29
35
query Foo {
30
36
dog {
31
37
name
32
38
}
33
39
}
34
- ` ,
35
- ) ;
40
+ ` ) ;
36
41
} ) ;
37
42
38
43
it ( 'with operation and fragment' , ( ) => {
39
- expectPassesRule (
40
- ExecutableDefinitions ,
41
- `
44
+ expectValid ( `
42
45
query Foo {
43
46
dog {
44
47
name
@@ -49,14 +52,11 @@ describe('Validate: Executable definitions', () => {
49
52
fragment Frag on Dog {
50
53
name
51
54
}
52
- ` ,
53
- ) ;
55
+ ` ) ;
54
56
} ) ;
55
57
56
58
it ( 'with type definition' , ( ) => {
57
- expectFailsRule (
58
- ExecutableDefinitions ,
59
- `
59
+ expectErrors ( `
60
60
query Foo {
61
61
dog {
62
62
name
@@ -70,18 +70,14 @@ describe('Validate: Executable definitions', () => {
70
70
extend type Dog {
71
71
color: String
72
72
}
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
+ ] ) ;
79
77
} ) ;
80
78
81
79
it ( 'with schema definition' , ( ) => {
82
- expectFailsRule (
83
- ExecutableDefinitions ,
84
- `
80
+ expectErrors ( `
85
81
schema {
86
82
query: Query
87
83
}
@@ -91,12 +87,10 @@ describe('Validate: Executable definitions', () => {
91
87
}
92
88
93
89
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
+ ] ) ;
101
95
} ) ;
102
96
} ) ;
0 commit comments