blog-be/test/article.e2e-spec.ts

34 lines
1008 B
TypeScript
Raw Normal View History

2021-04-24 14:47:45 +08:00
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from '../src/app.module';
import { GraphQLModule } from '@nestjs/graphql';
import {
ApolloServerTestClient,
createTestClient,
} from 'apollo-server-testing';
import { gql } from 'apollo-server-express';
describe('AppController (e2e)', () => {
let app: INestApplication;
let apolloClient: ApolloServerTestClient;
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
const module: GraphQLModule = moduleFixture.get<GraphQLModule>(
GraphQLModule,
);
// apolloServer is protected, we need to cast module to any to get it
apolloClient = createTestClient((module as any).apolloServer);
});
afterAll(async () => {
await app?.close();
});
});