create-graphql-server icon indicating copy to clipboard operation
create-graphql-server copied to clipboard

Add a testing strategy based on mongo mocking

Open tmeasday opened this issue 8 years ago • 0 comments

Here is some code that I've used:

  • Mocking the db: https://gist.github.com/tmeasday/f957de6c4c9c7ece790c2897ff2016d6

  • Running queries directly from tests: https://gist.github.com/tmeasday/51d0c9fe2d1b7acc5e1aece59b1ff658

Example test:

it('creates builds in the right state', async () => {
  const { createBuild: build } = await runQuery(
    db,
    gql`
      mutation {
        createBuild(input: { appId: "${appId}" }) {
          status
        }
      }
    `
  );

  expect(build).toEqual({
    status: 'BUILD_IN_PROGRESS',
  });
});

tmeasday avatar Aug 03 '17 01:08 tmeasday