Search code examples
testingmongoosesnapshotjestjsgraphql-js

How can I test a GraphQL server using Mongoose with Jest


I want to test queries against my graphql implementation that is connected to a mongoose database using jest snapshot feature

I would like to follow this approach: https://github.com/nodkz/graphql-compose-examples/blob/master/examples/user/tests/queriesFromIndex.js

To use Jest snapshot to test the result of my queries.

One drawback of this approach is that I need to pre populate my mongo database with the same dummy data to always get the same results

what are the approaches to test a graphql server? including mutations and subscriptions


Solution

  • I've wrote a blog post of how to solve this

    https://medium.com/@sibelius/testing-a-graphql-server-using-jest-4e00d0e4980e#.xpi0i3d59