Feedback for “Testing” - Please document how to handle generated GQL classes in Tests #2300
Replies: 4 comments 1 reply
-
@apazureck We've just run into the exact same problem with a newly generated angular project. |
Beta Was this translation helpful? Give feedback.
-
It's far from perfect but what will work is to provide the GQL in your TestBed:
You could write yourself a Wrapper, this will at least remove some of the boilerplate (if you need to provide multiple GQL at the same time)
But in my opinion it is still sad that this might be necessary. |
Beta Was this translation helpful? Give feedback.
-
I had the same problem. As a workaround I changed the imports in the generated file like this:
and then for every constructor: You might create a script which runs after the code generation, to do this for you. |
Beta Was this translation helpful? Give feedback.
-
I had the same problem too. I'm using Jest as test framework with jest-preset-angular. I could solve it by changing the {
"extends": "./tsconfig.json",
"compilerOptions": {
// Your compiler options
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
} to this: {
"extends": "./tsconfig.json",
"compilerOptions": {
// Your compiler options
},
"include": ["src/**/*.ts"] // Optionally you can still use `src/**/*.spec.ts` and `src/**/*.d.ts` and add the path to the graphql-codegen generated file.
} |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am currently struggleing using my generated GQLs for testing and cannot find any solution when searching online.
I have a component, which depends on a service using the generated GQL with Apollo Codegen:
Test:
Component:
Service:
FullConfigurationGQL:
So when I use the ApolloTestingModule I would expect it has some kind of provider for Apollo. But it does not seem so. This is my test error:
As you can see the service as well as the GQL have those tags, but the Apollo class does not. So how can I provide the mock to be used by the generated GQL class? It would be nice to use the controller in the long term for evaluating the queries.
And I know, I could and definitly should mock the service in the first place (which I will do in the future), but that would only postpone my problem. I would like to use the Apollo Mock there, if possible.
How can I do this?
If I figure something out I'll be happy to share it here and woudl gladly update the documentation.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions