Skip to content

Commit d75a78a

Browse files
sukvvonmanudeli
andauthored
test(query-core/mutations): add 'await' to 'sleep', remove 'vi.waitFor' and add 'advanceTimersByTimeAsync' (#9341)
Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
1 parent b805733 commit d75a78a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/query-core/src/__tests__/mutations.test.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ describe('mutations', () => {
397397
const onSuccess = vi.fn()
398398

399399
const mutation = new MutationObserver(queryClient, {
400-
mutationFn: () => {
401-
sleep(100)
400+
mutationFn: async () => {
401+
await sleep(100)
402402
return Promise.resolve('update')
403403
},
404404
onSuccess: () => {
@@ -409,16 +409,17 @@ describe('mutations', () => {
409409
void mutation.mutate()
410410

411411
mutation.setOptions({
412-
mutationFn: () => {
413-
sleep(100)
412+
mutationFn: async () => {
413+
await sleep(100)
414414
return Promise.resolve('update')
415415
},
416416
onSuccess: () => {
417417
onSuccess(2)
418418
},
419419
})
420420

421-
await vi.waitFor(() => expect(onSuccess).toHaveBeenCalledTimes(1))
421+
await vi.advanceTimersByTimeAsync(100)
422+
expect(onSuccess).toHaveBeenCalledTimes(1)
422423

423424
expect(onSuccess).toHaveBeenCalledWith(2)
424425
})

0 commit comments

Comments
 (0)