I'm using typegraphql, and i register DayOfWeek enum type using resgiterEnumType.
following is my enum and registerEnumType function, and they are in one file.
export enum DayOfWeek {
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
}
registerEnumType(DayOfWeek, {
name: "DayOfWeekType", // this one is mandatory
});
It works well when i run program. but when i run jest test I got an message like following
Looks like you've forgot to provide experimental metadata API polyfill.
12 | }
13 |
> 14 | registerEnumType(DayOfWeek, {
| ^
15 | name: "DayOfWeekType", // this one is mandatory
16 | });
17 |
If i put enum and registerEnumType in the same file, run works well and test is failed.
and If i separate enum and registerEnumType, graphql not found DayOfWeek type....
how can i solved that?
You need to add
import "reflect-metadata";
at the top of your file
import { Test, TestingModule } from '@nestjs/testing';
import { GraphQLModule } from '@nestjs/graphql';
describe('your test suite', () => {
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
GraphQLModule.forRoot({
...
}),
],
}).compile();
});
});
You need to provision GraphQLModule
in your spec.
P/S: the code-snippet above is under assumption that you're on NestJS
framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With