@@ -15,27 +15,9 @@ import { graphql } from '../graphql';
1515// 80+ char lines are useful in describe/it, so ignore in this file.
1616/*eslint-disable max-len */
1717
18- /**
19- * Helper function to test a query and the expected response.
20- */
21- function testQuery ( query , expected ) {
22- return expect (
23- graphql ( StarWarsSchema , query )
24- ) . to . become ( { data : expected } ) ;
25- }
26-
27- /**
28- * Helper function to test a query with params and the expected response.
29- */
30- function testQueryWithParams ( query , params , expected ) {
31- return expect (
32- graphql ( StarWarsSchema , query , null , params )
33- ) . to . become ( { data : expected } ) ;
34- }
35-
3618describe ( 'Star Wars Query Tests' , ( ) => {
3719 describe ( 'Basic Queries' , ( ) => {
38- it ( 'Correctly identifies R2-D2 as the hero of the Star Wars Saga' , ( ) => {
20+ it ( 'Correctly identifies R2-D2 as the hero of the Star Wars Saga' , async ( ) => {
3921 var query = `
4022 query HeroNameQuery {
4123 hero {
@@ -48,10 +30,11 @@ describe('Star Wars Query Tests', () => {
4830 name : 'R2-D2'
4931 }
5032 } ;
51- return testQuery ( query , expected ) ;
33+ var result = await graphql ( StarWarsSchema , query ) ;
34+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
5235 } ) ;
5336
54- it ( 'Allows us to query for the ID and friends of R2-D2' , ( ) => {
37+ it ( 'Allows us to query for the ID and friends of R2-D2' , async ( ) => {
5538 var query = `
5639 query HeroNameAndFriendsQuery {
5740 hero {
@@ -80,12 +63,13 @@ describe('Star Wars Query Tests', () => {
8063 ]
8164 }
8265 } ;
83- return testQuery ( query , expected ) ;
66+ var result = await graphql ( StarWarsSchema , query ) ;
67+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
8468 } ) ;
8569 } ) ;
8670
8771 describe ( 'Nested Queries' , ( ) => {
88- it ( 'Allows us to query for the friends of friends of R2-D2' , ( ) => {
72+ it ( 'Allows us to query for the friends of friends of R2-D2' , async ( ) => {
8973 var query = `
9074 query NestedQuery {
9175 hero {
@@ -158,12 +142,13 @@ describe('Star Wars Query Tests', () => {
158142 ]
159143 }
160144 } ;
161- return testQuery ( query , expected ) ;
145+ var result = await graphql ( StarWarsSchema , query ) ;
146+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
162147 } ) ;
163148 } ) ;
164149
165150 describe ( 'Using IDs and query parameters to refetch objects' , ( ) => {
166- it ( 'Allows us to query for Luke Skywalker directly, using his ID' , ( ) => {
151+ it ( 'Allows us to query for Luke Skywalker directly, using his ID' , async ( ) => {
167152 var query = `
168153 query FetchLukeQuery {
169154 human(id: "1000") {
@@ -176,10 +161,11 @@ describe('Star Wars Query Tests', () => {
176161 name : 'Luke Skywalker'
177162 }
178163 } ;
179- return testQuery ( query , expected ) ;
164+ var result = await graphql ( StarWarsSchema , query ) ;
165+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
180166 } ) ;
181167
182- it ( 'Allows us to create a generic query, then use it to fetch Luke Skywalker using his ID' , ( ) => {
168+ it ( 'Allows us to create a generic query, then use it to fetch Luke Skywalker using his ID' , async ( ) => {
183169 var query = `
184170 query FetchSomeIDQuery($someId: String!) {
185171 human(id: $someId) {
@@ -195,10 +181,11 @@ describe('Star Wars Query Tests', () => {
195181 name : 'Luke Skywalker'
196182 }
197183 } ;
198- return testQueryWithParams ( query , params , expected ) ;
184+ var result = await graphql ( StarWarsSchema , query , null , params ) ;
185+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
199186 } ) ;
200187
201- it ( 'Allows us to create a generic query, then use it to fetch Han Solo using his ID' , ( ) => {
188+ it ( 'Allows us to create a generic query, then use it to fetch Han Solo using his ID' , async ( ) => {
202189 var query = `
203190 query FetchSomeIDQuery($someId: String!) {
204191 human(id: $someId) {
@@ -214,10 +201,11 @@ describe('Star Wars Query Tests', () => {
214201 name : 'Han Solo'
215202 }
216203 } ;
217- return testQueryWithParams ( query , params , expected ) ;
204+ var result = await graphql ( StarWarsSchema , query , null , params ) ;
205+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
218206 } ) ;
219207
220- it ( 'Allows us to create a generic query, then pass an invalid ID to get null back' , ( ) => {
208+ it ( 'Allows us to create a generic query, then pass an invalid ID to get null back' , async ( ) => {
221209 var query = `
222210 query humanQuery($id: String!) {
223211 human(id: $id) {
@@ -231,12 +219,13 @@ describe('Star Wars Query Tests', () => {
231219 var expected = {
232220 human : null
233221 } ;
234- return testQueryWithParams ( query , params , expected ) ;
222+ var result = await graphql ( StarWarsSchema , query , null , params ) ;
223+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
235224 } ) ;
236225 } ) ;
237226
238227 describe ( 'Using aliases to change the key in the response' , ( ) => {
239- it ( 'Allows us to query for Luke, changing his key with an alias' , ( ) => {
228+ it ( 'Allows us to query for Luke, changing his key with an alias' , async ( ) => {
240229 var query = `
241230 query FetchLukeAliased {
242231 luke: human(id: "1000") {
@@ -249,10 +238,11 @@ describe('Star Wars Query Tests', () => {
249238 name : 'Luke Skywalker'
250239 } ,
251240 } ;
252- return testQuery ( query , expected ) ;
241+ var result = await graphql ( StarWarsSchema , query ) ;
242+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
253243 } ) ;
254244
255- it ( 'Allows us to query for both Luke and Leia, using two root fields and an alias' , ( ) => {
245+ it ( 'Allows us to query for both Luke and Leia, using two root fields and an alias' , async ( ) => {
256246 var query = `
257247 query FetchLukeAndLeiaAliased {
258248 luke: human(id: "1000") {
@@ -271,12 +261,13 @@ describe('Star Wars Query Tests', () => {
271261 name : 'Leia Organa'
272262 }
273263 } ;
274- return testQuery ( query , expected ) ;
264+ var result = await graphql ( StarWarsSchema , query ) ;
265+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
275266 } ) ;
276267 } ) ;
277268
278269 describe ( 'Uses fragments to express more complex queries' , ( ) => {
279- it ( 'Allows us to query using duplicated content' , ( ) => {
270+ it ( 'Allows us to query using duplicated content' , async ( ) => {
280271 var query = `
281272 query DuplicateFields {
282273 luke: human(id: "1000") {
@@ -299,10 +290,11 @@ describe('Star Wars Query Tests', () => {
299290 homePlanet : 'Alderaan'
300291 }
301292 } ;
302- return testQuery ( query , expected ) ;
293+ var result = await graphql ( StarWarsSchema , query ) ;
294+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
303295 } ) ;
304296
305- it ( 'Allows us to use a fragment to avoid duplicating content' , ( ) => {
297+ it ( 'Allows us to use a fragment to avoid duplicating content' , async ( ) => {
306298 var query = `
307299 query UseFragment {
308300 luke: human(id: "1000") {
@@ -328,12 +320,13 @@ describe('Star Wars Query Tests', () => {
328320 homePlanet : 'Alderaan'
329321 }
330322 } ;
331- return testQuery ( query , expected ) ;
323+ var result = await graphql ( StarWarsSchema , query ) ;
324+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
332325 } ) ;
333326 } ) ;
334327
335328 describe ( 'Using __typename to find the type of an object' , ( ) => {
336- it ( 'Allows us to verify that R2-D2 is a droid' , ( ) => {
329+ it ( 'Allows us to verify that R2-D2 is a droid' , async ( ) => {
337330 var query = `
338331 query CheckTypeOfR2 {
339332 hero {
@@ -348,7 +341,8 @@ describe('Star Wars Query Tests', () => {
348341 name : 'R2-D2'
349342 } ,
350343 } ;
351- return testQuery ( query , expected ) ;
344+ var result = await graphql ( StarWarsSchema , query ) ;
345+ expect ( result ) . to . deep . equal ( { data : expected } ) ;
352346 } ) ;
353347 } ) ;
354348} ) ;
0 commit comments