You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reading out query signals in template causes test failure #9910
I'm running on Angular 21 and I'm unit testing with Vitest, I have this component:
@Component({selector: 'app-root',template: ` <!-- comment out the line below and the test passes --> {{ numbersQuery.isSuccess() }} `,})exportclassApp{numbersQuery=injectQuery(()=>({queryKey: ['stuff'],queryFn: ()=>Promise.resolve([1,2,3,4,5]),}));}
And I have this test for it:
describe('App',()=>{letsut: App;letfixture: ComponentFixture<App>;beforeEach(async()=>{awaitTestBed.configureTestingModule({providers: [provideTanStackQuery(newQueryClient())],imports: [App],}).compileComponents();fixture=TestBed.createComponent(App);sut=fixture.componentInstance;});it('fires a query',async()=>{awaittriggerQueries(fixture);expect(sut.numbersQuery.isSuccess()).toBe(true);expect(sut.numbersQuery.data()).toEqual([1,2,3,4,5]);});});consttriggerQueries=async(fixture: ComponentFixture<unknown>)=>{// Kick off effects & queriesfixture.detectChanges();// Wait for TanStack Query + Angular to settleawaitfixture.whenStable();// Apply final results to the template / signalsfixture.detectChanges();};
But seemingly, using the .isSuccess() signal inside the template of the component is causing the behavior of the query signals to malfunction or something: isSuccess() returns false, data() is undefined. When I comment out the {{ numbersQuery.isSuccess() }}, the test passes without problems.
Activity
JPtenBerge commentedon Nov 25, 2025
Also, as a workaround: overriding the template makes the test pass.
JPtenBerge commentedon Nov 25, 2025
Oh, it's not just within the template. Any call to a query signal will cause strange behavior, like in an
effect():No workaround for this yet.
TkDodo commentedon Dec 27, 2025
@arnoud-dv can you have a look please