UNPKG

@graphql-yoga/nestjs

Version:

GraphQL Yoga driver for NestJS GraphQL.

51 lines (46 loc) 1.09 kB
import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { fetch } from '@whatwg-node/fetch'; import { AppModule } from './fixtures/graphql/app.module'; let app: INestApplication, url: string; beforeAll(async () => { const module = await Test.createTestingModule({ imports: [AppModule.forRoot()], }).compile(); app = module.createNestApplication(); await app.listen(0); url = (await app.getUrl()) + '/graphql'; }); afterAll(() => app.close()); it('should return query result', async () => { const res = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', }, body: JSON.stringify({ query: /* GraphQL */ ` { getCats { id color weight } } `, }), }); await expect(res.json()).resolves.toMatchInlineSnapshot(` { "data": { "getCats": [ { "color": "black", "id": 1, "weight": 5, }, ], }, } `); });