首页 > 解决方案 > 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

标签: jestjsgraphqlnestjsbabel-jestmikro-orm

解决方案


推荐阅读