@@ -26,12 +26,12 @@ describe("GraphQLInteraction", () => {
26
26
} ) ;
27
27
} ) ;
28
28
describe ( "when no operation is provided" , ( ) => {
29
- it ( "should marshal to null " , ( ) => {
29
+ it ( "should not be present in unmarshaled body " , ( ) => {
30
30
interaction . uponReceiving ( "a request" ) ;
31
31
interaction . withQuery ( "{ hello }" ) ;
32
32
33
33
const json : any = interaction . json ( ) ;
34
- expect ( json . request . body . operationName ) . to . eq ( null ) ;
34
+ expect ( json . request . body ) . to . not . have . property ( "operationName" ) ;
35
35
} ) ;
36
36
} ) ;
37
37
describe ( "when given an invalid operation" , ( ) => {
@@ -48,13 +48,23 @@ describe("GraphQLInteraction", () => {
48
48
interaction . withOperation ( "query" ) ;
49
49
interaction . withQuery ( "{ hello }" ) ;
50
50
interaction . withVariables ( {
51
- foo : "bar" ,
51
+ foo : "bar"
52
52
} ) ;
53
53
54
54
const json : any = interaction . json ( ) ;
55
55
expect ( json . request . body . variables ) . to . deep . eq ( { foo : "bar" } ) ;
56
56
} ) ;
57
57
} ) ;
58
+ describe ( "when no variables are provided" , ( ) => {
59
+ it ( "should not add the variables property to the payload" , ( ) => {
60
+ interaction . uponReceiving ( "a request" ) ;
61
+ interaction . withOperation ( "query" ) ;
62
+ interaction . withQuery ( "{ hello }" ) ;
63
+
64
+ const json : any = interaction . json ( ) ;
65
+ expect ( json . request . body ) . to . not . have . property ( "variables" ) ;
66
+ } ) ;
67
+ } ) ;
58
68
} ) ;
59
69
60
70
describe ( "#withQuery" , ( ) => {
@@ -63,13 +73,15 @@ describe("GraphQLInteraction", () => {
63
73
interaction . withOperation ( "query" ) ;
64
74
interaction . withQuery ( "{ hello }" ) ;
65
75
interaction . withVariables ( {
66
- foo : "bar" ,
76
+ foo : "bar"
67
77
} ) ;
68
78
} ) ;
69
79
70
80
describe ( "when given an invalid query" , ( ) => {
71
81
it ( "should fail with an error" , ( ) => {
72
- expect ( ( ) => interaction . withQuery ( "{ not properly terminated" ) ) . to . throw ( Error ) ;
82
+ expect ( ( ) =>
83
+ interaction . withQuery ( "{ not properly terminated" )
84
+ ) . to . throw ( Error ) ;
73
85
} ) ;
74
86
} ) ;
75
87
@@ -101,7 +113,7 @@ describe("GraphQLInteraction", () => {
101
113
}
102
114
}` ) ;
103
115
interaction . withVariables ( {
104
- name : "bar" ,
116
+ name : "bar"
105
117
} ) ;
106
118
const json : any = interaction . json ( ) ;
107
119
@@ -110,9 +122,7 @@ describe("GraphQLInteraction", () => {
110
122
const lotsOfWhitespace = `{ Hello(id: \$id) { name } }` ;
111
123
expect ( r . test ( lotsOfWhitespace ) ) . to . eq ( true ) ;
112
124
} ) ;
113
-
114
125
} ) ;
115
126
} ) ;
116
127
} ) ;
117
-
118
128
} ) ;
0 commit comments