@@ -50,25 +50,34 @@ describe('injectMutation', () => {
5050 it ( 'should change state after invoking mutate' , async ( ) => {
5151 const result = 'Mock data'
5252
53- const mutation = TestBed . runInInjectionContext ( ( ) => {
54- return injectMutation ( ( ) => ( {
53+ @Component ( {
54+ template : `
55+ <div>isIdle: {{ mutation.isIdle() }}</div>
56+ <div>isPending: {{ mutation.isPending() }}</div>
57+ <div>isError: {{ mutation.isError() }}</div>
58+ <div>isSuccess: {{ mutation.isSuccess() }}</div>
59+ <div>data: {{ mutation.data() ?? 'none' }}</div>
60+ <div>error: {{ mutation.error()?.message ?? 'none' }}</div>
61+ ` ,
62+ } )
63+ class Page {
64+ readonly mutation = injectMutation ( ( ) => ( {
5565 mutationFn : ( params : string ) => sleep ( 10 ) . then ( ( ) => params ) ,
5666 } ) )
57- } )
67+ }
5868
59- TestBed . tick ( )
69+ const rendered = await render ( Page )
6070
61- mutation . mutate ( result )
71+ rendered . fixture . componentInstance . mutation . mutate ( result )
6272 await vi . advanceTimersByTimeAsync ( 0 )
73+ rendered . fixture . detectChanges ( )
6374
64- expectSignals ( mutation , {
65- isIdle : false ,
66- isPending : true ,
67- isError : false ,
68- isSuccess : false ,
69- data : undefined ,
70- error : null ,
71- } )
75+ expect ( rendered . getByText ( 'isIdle: false' ) ) . toBeInTheDocument ( )
76+ expect ( rendered . getByText ( 'isPending: true' ) ) . toBeInTheDocument ( )
77+ expect ( rendered . getByText ( 'isError: false' ) ) . toBeInTheDocument ( )
78+ expect ( rendered . getByText ( 'isSuccess: false' ) ) . toBeInTheDocument ( )
79+ expect ( rendered . getByText ( 'data: none' ) ) . toBeInTheDocument ( )
80+ expect ( rendered . getByText ( 'error: none' ) ) . toBeInTheDocument ( )
7281 } )
7382
7483 it ( 'should return error when request fails' , async ( ) => {
0 commit comments