-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to test codegen services with jest #1703
Comments
I think we have similar issue after upgrading from angular 11 to 12.
I get this error while testing with jest:
Shouldn't the |
I have the same as @pafflique with generated code, it started after upgrading to jest 27. But I could also workaround by changing the generated code to not use namespace import:
to
and changing the respective references too. I started with this test, because I found some |
just did a test.
in test-setup.ts (jest setup file) of the app to test, it works without changing the generated code. |
Here are some related issues: |
I found too my workaround was instable. But maybe I found it which could also fix your problem. So my current workaround is: /**
* TODO: workaround for https://github.com/kamilkisiela/apollo-angular/issues/1703
*
* has to be called in `test-setup.ts`:
*
* ```
* import { Apollo, ApolloBase } from 'apollo-angular';
* import { fixApolloBase } from './workaround';
* fixApolloBase(Apollo, ApolloBase);
*
* ```
*
* @param _apollo `Apollo` has to be imported by the caller (forces the called to do so)
* @param apolloBase `ApolloBase` has to be imported by the caller (forces the called to do so)
* @returns
*/
export function fixApolloBase(
_apollo: typeof Apollo,
apolloBase: typeof ApolloBase
) {
return Injectable()(apolloBase);
} Then import and execute the function from within import { Apollo, ApolloBase } from 'apollo-angular';
import { fixApolloBase } from './workaround';
fixApolloBase(Apollo, ApolloBase); At least in my case this helped in multiple libs. |
@spali How does your jest.config look like. Above workaround does not work for me right now. |
@Nielsb85 I use an NX workspace with default generated jest.config. the workspace
the workspace
the library
|
@Nielsb85 I forget to mention.... be sure to clear jest cache before running tests and if it's a NX workspace to skip the nx-cache |
@spali Thanks. Cache was already cleared. No luck so far. |
I used a "direct flavor" of the workaround.
|
It has been very difficult to trace this issue to its actual cause, but this is the actual bug: thymikee/jest-preset-angular#963 The issue appears because |
thanks Maximaximum |
Describe the bug
We are using NX for our monorepo and created a library that is responsible for the generation and exposure of GraphQL services using codegen as suggested here.
Using said services in our components works just fine. However, when it comes to testing (Jest), we get an error saying:
Can't resolve all parameters for GetExampleGQL: (?).
To Reproduce
1. Create a Library with nx using the following
codegen.yml
and export the generated services2. Use the generated services in a Jest test
3. Run tests
yarn nx test my-project --detect-open-handles
Outputs:
Expected behavior
The test should pass.
Environment:
It would be nice if someone could share if I am doing something wrong in the test.
The text was updated successfully, but these errors were encountered: