Skip to content

Test at the end of Section 4 does not run #24

@mullaney

Description

@mullaney

I have been working my way through this tutorial and really enjoying it. However, I've run into a problem testing. At the end of section 4, here is the state of my code: https://github.com/mullaney/nexus-js-tutorial/tree/28ac581142ac2f49ac46d3769e7810fc13ffb82b

I believe I followed all the instructions in section 4, however, I get the following error when I run npm run test:

{17:27}[ruby-3.0.0]‹node-15.4.0›~/Code/nexus-tutorial:main ✗ ➭ npm run test 
> nexus-tutorial@1.0.0 test
> npm run generate && jest


> nexus-tutorial@1.0.0 generate
> ts-node --transpile-only api/schema

 FAIL  tests/Post.test.ts
  ✕ ensures that a draft can be created and published (45 ms)

  ● ensures that a draft can be created and published

    called start() with surprising state started

      at ApolloServer.<anonymous> (node_modules/apollo-server-core/src/ApolloServer.ts:510:13)
      at node_modules/apollo-server-core/dist/ApolloServer.js:8:71
      at Object.<anonymous>.__awaiter (node_modules/apollo-server-core/dist/ApolloServer.js:4:12)
      at ApolloServer._start (node_modules/apollo-server-core/dist/ApolloServer.js:226:16)
      at ApolloServer.<anonymous> (node_modules/apollo-server/src/index.ts:108:16)
      at node_modules/apollo-server/dist/index.js:18:71

  ● ensures that a draft can be created and published

    TypeError: Cannot read property 'request' of undefined

       5 | it('ensures that a draft can be created and published', async () => {
       6 |   // Create a new draft
    >  7 |   const draftResult = await ctx.client.request(`
         |                                        ^
       8 |     mutation {
       9 |       createDraft(title: "Nexus", body: "...") {
      10 |         id

      at Object.<anonymous> (tests/Post.test.ts:7:40)

  console.log
    🚀 Server ready at http://localhost:4000/

      at api/server.ts:8:11

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        0.622 s, estimated 1 s
Ran all test suites.
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

The function createTestContext doesn't seem to be assigning a value to the client key as it's supposed to. Can someone offer me any help with how to get unstuck?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions