T
TanStack17mo ago
fair-rose

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
fair-rose
fair-roseOP17mo ago
However if I remove the Provider then I get nullInjector error
ratty-blush
ratty-blush16mo 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.
protestant-coral
protestant-coral16mo 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
fair-rose
fair-roseOP16mo ago
Yeah this was the solution! Thanks so much

Did you find this page helpful?