jestjs - NestJS / GraphQL e2e 测试错误:“PickObjectType”的“id”字段的默认值不匹配导致的错误。确保这些 val
问题描述
使用 NestJS GraphQL 运行 e2e 测试时,我收到以下错误。然而,测试运行平稳,执行,产生了想要的结果。只是由于以下错误导致测试失败:
Error caused by mis-matched default values for the "id" field of "PickObjectType". The default value from the decorator "48469fd4-dee8-464b-a8d5-797ba8071f22" is not equal to the property initializer value "f221ed1e-c370-471c-9042-27ddd995ed33". Ensure that these values match.
at Object.getDefaultValue (../node_modules/@nestjs/graphql/dist/schema-builder/helpers/get-default-value.helper.js:13:15)
at ../node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type-definition.factory.js:43:76
at Array.forEach (<anonymous>)
at ../node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type-definition.factory.js:42:33
at resolveThunk (../node_modules/graphql/type/definition.js:480:40)
at defineInputFieldMap (../node_modules/graphql/type/definition.js:1207:18)
at GraphQLInputObjectType.getFields (../node_modules/graphql/type/definition.js:1155:27)
at TypeFieldsAccessor.extractFromInputType (../node_modules/@nestjs/graphql/dist/schema-builder/services/type-fields.accessor.js:9:35)
at ../node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type-definition.factory.js:56:66
at resolveThunk (../node_modules/graphql/type/definition.js:480:40)
有没有人见过这个?
这是测试:
....
beforeEach(async () => {
jest.useFakeTimers();
mikroOrmConfig.tsNode = true; // enforce TS mode for tests so we discover TS entities even if ts-node is not detected properly
const module = await Test.createTestingModule({
imports: [AppModule],
controllers: [],
providers: [
OrganizationInvitationResolver,
OrganizationInvitationService,
CaslAbilityFactory,
],
}).compile();
app = module.createNestApplication();
await app.init();
appRequest = request(app.getHttpServer());
organizationInvitationResolver = module.get<OrganizationInvitationResolver>(
OrganizationInvitationResolver,
);
orm = module.get<MikroORM>(MikroORM);
organizationInvitationRepository = orm.em.getRepository(
OrganizationInvitation,
);
});
...
it('creates a new organizationInvitation with the parameter reservedComment', async () => {
return await appRequest
.post(GRAPHQL_ENDPOINT_PATH)
.send({
query: `mutation createOrganizationInvitation {
createOrganizationInvitation(reservedComment: "test test") {
id
activationCode
reservedComment
isPriojetActivationCode
}
}`,
variables: {},
})
.expect((res) => {
console.log('this is the result', res.text);
console.log('this is the result', res.statusCode);
console.log('this is the result', res.body);
expect(
res.body.data.createOrganizationInvitation.reservedComment,
).toEqual('test test');
});
非常感谢您的任何提示!也在这里发布:https ://github.com/nestjs/graphql/issues/1626
解决方案
推荐阅读
- mysql - 删除对索引列有约束的行(非唯一)mySQL InnoDB
- android - 如何创建一个用户类并在我的整个项目中查阅它?
- angularjs - AngularJS + Ionic 5 标签导航
- python-3.x - 使用 docker-compose 运行时无法让 Flask 应用程序与 Tensorflow Serving 通信
- typescript - 如何注释模板中的类型?
- excel - 如何从用户窗体列表框中的 0+n 列中获取文本?
- python - 如何用python解析复杂的json?
- python - 如何停止在 mathplotlib 中重叠的多个子图?
- python-3.x - 为什么在 python 中取模时 pow() 和 ** 的运行时间有很大差异?
- spring-boot - Wicket-Springboot 实现