When running an e2e test with NestJS GraphQL, I am receiving the following error. The test however runs smoothly, executes, produces the wanted result. It is just that the test fails due to the error below:
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)
Has anyone seen this before?
Here is the test:
....
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');
});
Thank you so much for any hints! Also posted it here: https://github.com/nestjs/graphql/issues/1626