[我用pyramida graphql API创建了一个嵌套js。如何为我的api创建并运行一些e2e测试。如果可以对我的登台数据库运行测试,那将是理想的选择。下面是我的出发点。但是我不确定我需要在哪里定义我的prisma服务以及如何在测试中使用它。
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
UserModule,
GraphQLModule.forRoot({
autoSchemaFile: 'src/schema.graphql',
}),
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
亲切的问候,
Gerry
您有一个选择是创建一个PrismaService
(或与您在服务器中通常提供的名称相同的另一个提供程序),它使用为测试环境(即测试数据库)配置的graphqlconfig
文件,无论是sqlite还是基于docker的数据库)。然后,您可以将PrismaService
添加到providers
的TestModule
数组中。
Disclaimer:我还没有这样做,只是在我自己的应用程序中使用了DatabaseService
做类似的事情。