-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Cannot find module @tanstack/angular-query-experimental in jest test #8364
Comments
This is probably due to Jest not directly supporting ES modules so these need to be transformed to commonjs. I don't think 5.60.0 is actually the cut off point where it doesn't work anymore as I got that version working with Jest locally with your repro code. If you have a choice I would suggest to move to Vitest, its API is almost identical to Jest, is much faster and has full support for ESM. But many people still depend on Jest so I will look into this, if anyone has any ideas how to fix this please add a comment. |
Hi, @ThiloAschebrock this should be fixed in v5.61.6. I cannot reproduce it anymore with that version. Please let me know if this solves it for you too. |
Hi @arnoud-dv, I would love to switch to vitest, but without switching to the analogjs platform this yet seems to be largely unsupported for Angular. |
Actually, while this is fixing the import, it now throws the following issue when actually running a test that uses Tanstack Query with jest:
|
I changed the test in your repro to this: import {fakeAsync, TestBed, tick} from '@angular/core/testing';
import {
injectQuery,
provideTanStackQuery,
QueryClient,
} from '@tanstack/angular-query-experimental';
describe('TanstackQuery', () => {
it('testing', fakeAsync(() => {
TestBed.configureTestingModule({
providers: [provideTanStackQuery(new QueryClient())],
});
const query = TestBed.runInInjectionContext(() =>
injectQuery(() => ({
queryKey: ['todos'],
queryFn: () =>
Promise.resolve('some data')
})),
)
tick()
expect(query.data()).toBe('some data');
}))
}); And it runs green. What version of Jest and Node are you using? |
If I add TestBed.configureTestingModule({
providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
}); |
Thank you very much for investigating. You are correct that this error is triggered by including the dev tools. This came up for my project, as I had abstracted the the provider setup into a custom provider function so that I can easily run the tests with the same query client configuration as used in the application. Obviously, the dev tools part wasn't needed in the unit tests and, consequently, I was able to resolve this issue by splitting the application and test setup for TanStack Query. |
Describe the bug
I am using Angulary Query in conjunction with test setup with jest. Ever since Angular Query version 5.60.0, all tests that import from
@tanstack/angular-query-experimental
fail withCannot find module '@tanstack/angular-query-experimental'
:See minimal example at https://stackblitz.com/edit/qiyn4c. All versions up to 5.59.20 are able to import without issues though.
Your minimal, reproducible example
https://stackblitz.com/edit/qiyn4c
Steps to reproduce
npm test
in the consoleExpected behavior
Jest test able to import from @tanstack/angular-query-experimental.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Node 20, 22
Tanstack Query adapter
angular-query
TanStack Query version
v5.61.5
TypeScript version
v5.6.3
Additional context
I understand that this might require a configuration change in my test setup, but am still wondering what changes in 2459701 triggered this issues and if this was an intentional change.
The text was updated successfully, but these errors were encountered: