Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start the test server before running tests.
GraphQL
beforeAll(async () => { await server.[1](); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using stop instead of start will shut down the server before tests.
✗ Incorrect
The start method launches the test server so tests can run against it.
2fill in blank
mediumComplete the code to send a GraphQL query to the test server.
GraphQL
const response = await server.executeOperation({ query: [1] }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a mutation or subscription instead of a query.
✗ Incorrect
You need to pass the GraphQL query string or document. GET_USERS_QUERY is the correct query here.
3fill in blank
hardFix the error in the test assertion to check the response status code.
GraphQL
expect(response.[1]).toBe(200);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using statusCode or code which are not standard in this context.
✗ Incorrect
The correct property for HTTP status in the response is status.
4fill in blank
hardFill both blanks to correctly close the test server after all tests.
GraphQL
afterAll(async () => { await server.[1](); await server.[2](); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using start or restart instead of stop or close.
✗ Incorrect
First, stop the server, then close any open connections.
5fill in blank
hardFill all three blanks to write a test that sends a mutation and checks the response data.
GraphQL
test('adds a user', async () => { const response = await server.executeOperation({ query: [1], variables: { name: [2] } }); expect(response.data.[3]).toBeDefined(); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a query instead of mutation, missing quotes around name, or wrong response field.
✗ Incorrect
The mutation is ADD_USER_MUTATION, the variable name is the string 'Alice', and the response field is addUser.