@@ -316,7 +316,6 @@ describe('injectMutation', () => {
316316 <button (click)="mutate()"></button>
317317 <span>{{ mutation.data() }}</span>
318318 ` ,
319- standalone : true ,
320319 } )
321320 class FakeComponent {
322321 name = input . required < string > ( )
@@ -339,8 +338,6 @@ describe('injectMutation', () => {
339338 button . triggerEventHandler ( 'click' )
340339
341340 await resolveMutations ( )
342- fixture . detectChanges ( )
343-
344341 const text = debugElement . query ( By . css ( 'span' ) ) . nativeElement . textContent
345342 expect ( text ) . toEqual ( 'value' )
346343 const mutation = mutationCache . find ( { mutationKey : [ 'fake' , 'value' ] } )
@@ -357,7 +354,6 @@ describe('injectMutation', () => {
357354 <button (click)="mutate()"></button>
358355 <span>{{ mutation.data() }}</span>
359356 ` ,
360- standalone : true ,
361357 } )
362358 class FakeComponent {
363359 name = input . required < string > ( )
@@ -400,6 +396,37 @@ describe('injectMutation', () => {
400396 expect ( mutation2 ! . options . mutationKey ) . toEqual ( [ 'fake' , 'updatedValue' ] )
401397 } )
402398
399+ test ( 'should have pending state when mutating in constructor' , async ( ) => {
400+ @Component ( {
401+ selector : 'app-fake' ,
402+ template : `
403+ <span>{{ mutation.isPending() ? 'pending' : 'not pending' }}</span>
404+ ` ,
405+ } )
406+ class FakeComponent {
407+ mutation = injectMutation ( ( ) => ( {
408+ mutationKey : [ 'fake' ] ,
409+ mutationFn : ( ) => sleep ( 0 ) . then ( ( ) => 'fake' ) ,
410+ } ) )
411+
412+ constructor ( ) {
413+ this . mutation . mutate ( )
414+ }
415+ }
416+
417+ const fixture = TestBed . createComponent ( FakeComponent )
418+ const { debugElement } = fixture
419+ const span = debugElement . query ( By . css ( 'span' ) )
420+
421+ vi . advanceTimersByTime ( 1 )
422+
423+ expect ( span . nativeElement . textContent ) . toEqual ( 'pending' )
424+
425+ await resolveMutations ( )
426+
427+ expect ( span . nativeElement . textContent ) . toEqual ( 'not pending' )
428+ } )
429+
403430 describe ( 'throwOnError' , ( ) => {
404431 test ( 'should evaluate throwOnError when mutation is expected to throw' , async ( ) => {
405432 const err = new Error ( 'Expected mock error. All is well!' )
0 commit comments