@@ -72,25 +72,36 @@ describe('injectMutation', () => {
7272 } )
7373
7474 it ( 'should return error when request fails' , async ( ) => {
75- const mutation = TestBed . runInInjectionContext ( ( ) => {
76- return injectMutation ( ( ) => ( {
75+ @Component ( {
76+ template : `
77+ <div>isIdle: {{ mutation.isIdle() }}</div>
78+ <div>isPending: {{ mutation.isPending() }}</div>
79+ <div>isError: {{ mutation.isError() }}</div>
80+ <div>isSuccess: {{ mutation.isSuccess() }}</div>
81+ <div>data: {{ mutation.data() ?? 'none' }}</div>
82+ <div>error: {{ mutation.error()?.message ?? 'none' }}</div>
83+ ` ,
84+ } )
85+ class Page {
86+ readonly mutation = injectMutation ( ( ) => ( {
7787 mutationFn : ( ) =>
7888 sleep ( 10 ) . then ( ( ) => Promise . reject ( new Error ( 'Some error' ) ) ) ,
7989 } ) )
80- } )
90+ }
8191
82- mutation . mutate ( )
92+ const rendered = await render ( Page )
93+
94+ rendered . fixture . componentInstance . mutation . mutate ( )
8395
8496 await vi . advanceTimersByTimeAsync ( 11 )
97+ rendered . fixture . detectChanges ( )
8598
86- expectSignals ( mutation , {
87- isIdle : false ,
88- isPending : false ,
89- isError : true ,
90- isSuccess : false ,
91- data : undefined ,
92- error : Error ( 'Some error' ) ,
93- } )
99+ expect ( rendered . getByText ( 'isIdle: false' ) ) . toBeInTheDocument ( )
100+ expect ( rendered . getByText ( 'isPending: false' ) ) . toBeInTheDocument ( )
101+ expect ( rendered . getByText ( 'isError: true' ) ) . toBeInTheDocument ( )
102+ expect ( rendered . getByText ( 'isSuccess: false' ) ) . toBeInTheDocument ( )
103+ expect ( rendered . getByText ( 'data: none' ) ) . toBeInTheDocument ( )
104+ expect ( rendered . getByText ( 'error: Some error' ) ) . toBeInTheDocument ( )
94105 } )
95106
96107 it ( 'should return data when request succeeds' , async ( ) => {
0 commit comments