Skip to content

Commit 522e903

Browse files
committed
test(angular-query-experimental/injectMutation): add test for 'mutateAsync' resolving with 'mutationFn' return value
1 parent 72a15ae commit 522e903

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,21 @@ describe('injectMutation', () => {
518518
await expect(() => mutateAsync()).rejects.toThrow(err)
519519
})
520520

521+
it('should resolve mutateAsync with the value returned from mutationFn', async () => {
522+
const key = queryKey()
523+
const { mutateAsync } = TestBed.runInInjectionContext(() => {
524+
return injectMutation(() => ({
525+
mutationKey: key,
526+
mutationFn: (params: string) => sleep(10).then(() => params),
527+
}))
528+
})
529+
530+
const promise = mutateAsync('Mock data')
531+
await vi.advanceTimersByTimeAsync(11)
532+
533+
await expect(promise).resolves.toBe('Mock data')
534+
})
535+
521536
describe('injection context', () => {
522537
it('should throw NG0203 with descriptive error outside injection context', () => {
523538
const key = queryKey()

0 commit comments

Comments
 (0)