T
TanStack14mo ago
conscious-sapphire

Provide angular query in spec file

When I provideQueryClient(() => new QueryClient()) in a spec file for jest testa I get random errors that say cannot read properties of undefined reading
4 Replies
conscious-sapphire
conscious-sapphireOP14mo ago
However if I remove the Provider then I get nullInjector error
wise-white
wise-white13mo ago
Maybe try provideAngularQuery instead?
await TestBed.configureTestingModule({
imports: [MyComponent],
providers: [
provideAngularQuery(new QueryClient()),
],
}).compileComponents();
await TestBed.configureTestingModule({
imports: [MyComponent],
providers: [
provideAngularQuery(new QueryClient()),
],
}).compileComponents();
However, both this and provideQueryClient(() => new QueryClient()) work for me, so it may be something completely different.
jolly-crimson
jolly-crimson13mo ago
I don't know what the random errors are exactly without more information. But recently I got TypeScript errors on queries in Jest unit tests in a NX monorepo which were resolved by removing preserveSymlinks: true from tsconfig.spec.json
conscious-sapphire
conscious-sapphireOP13mo ago
Yeah this was the solution! Thanks so much

Did you find this page helpful?