Skip to content

Commit 88f08e9

Browse files
committed
Change .toHaveBeenCalledTimes(1) to .toHaveBeenCalledOnce()
1 parent a34e8b7 commit 88f08e9

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

packages/toolkit/src/query/tests/buildThunks.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('re-triggering behavior on arg change', () => {
102102
expect(result.current.status).not.toBe('pending')
103103
})
104104

105-
expect(spy).toHaveBeenCalledTimes(1)
105+
expect(spy).toHaveBeenCalledOnce()
106106

107107
for (let x = 1; x < 3; x++) {
108108
rerender(6)
@@ -133,7 +133,7 @@ describe('re-triggering behavior on arg change', () => {
133133
await waitFor(() => {
134134
expect(result.current.status).not.toBe('pending')
135135
})
136-
expect(spy).toHaveBeenCalledTimes(1)
136+
expect(spy).toHaveBeenCalledOnce()
137137

138138
for (let x = 1; x < 3; x++) {
139139
rerender({ name: 'Bob', likes: 'waffles' })
@@ -166,7 +166,7 @@ describe('re-triggering behavior on arg change', () => {
166166
await waitFor(() => {
167167
expect(result.current.status).not.toBe('pending')
168168
})
169-
expect(spy).toHaveBeenCalledTimes(1)
169+
expect(spy).toHaveBeenCalledOnce()
170170

171171
for (let x = 1; x < 3; x++) {
172172
rerender({ person: { name: name + x } })
@@ -189,14 +189,14 @@ describe('re-triggering behavior on arg change', () => {
189189
await waitFor(() => {
190190
expect(result.current.status).not.toBe('pending')
191191
})
192-
expect(spy).toHaveBeenCalledTimes(1)
192+
expect(spy).toHaveBeenCalledOnce()
193193

194194
for (let x = 1; x < 3; x++) {
195195
rerender({ likes: 'Bananas', name: 'Tim' })
196196
await waitFor(() => {
197197
expect(result.current.status).not.toBe('pending')
198198
})
199-
expect(spy).toHaveBeenCalledTimes(1)
199+
expect(spy).toHaveBeenCalledOnce()
200200
}
201201
})
202202
})

packages/toolkit/src/query/tests/cacheLifecycle.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ test('updateCachedData', async () => {
515515
draft.value = 'TEST'
516516
trackCalls()
517517
})
518-
expect(trackCalls).toHaveBeenCalledTimes(1)
518+
expect(trackCalls).toHaveBeenCalledOnce()
519519
expect(getCacheEntry().data).toEqual({ value: 'TEST' })
520520

521521
await cacheEntryRemoved
@@ -526,7 +526,7 @@ test('updateCachedData', async () => {
526526
draft.value = 'TEST2'
527527
trackCalls()
528528
})
529-
expect(trackCalls).toHaveBeenCalledTimes(1)
529+
expect(trackCalls).toHaveBeenCalledOnce()
530530
expect(getCacheEntry().data).toEqual(undefined)
531531

532532
onCleanup()
@@ -564,15 +564,15 @@ test('dispatching further actions does not trigger another lifecycle', async ()
564564
}),
565565
})
566566
await storeRef.store.dispatch(extended.endpoints.injected.initiate())
567-
expect(onNewCacheEntry).toHaveBeenCalledTimes(1)
567+
expect(onNewCacheEntry).toHaveBeenCalledOnce()
568568

569569
await storeRef.store.dispatch(extended.endpoints.injected.initiate())
570-
expect(onNewCacheEntry).toHaveBeenCalledTimes(1)
570+
expect(onNewCacheEntry).toHaveBeenCalledOnce()
571571

572572
await storeRef.store.dispatch(
573573
extended.endpoints.injected.initiate(undefined, { forceRefetch: true }),
574574
)
575-
expect(onNewCacheEntry).toHaveBeenCalledTimes(1)
575+
expect(onNewCacheEntry).toHaveBeenCalledOnce()
576576
})
577577

578578
test('dispatching a query initializer with `subscribe: false` does also start a lifecycle', async () => {
@@ -590,11 +590,11 @@ test('dispatching a query initializer with `subscribe: false` does also start a
590590
await storeRef.store.dispatch(
591591
extended.endpoints.injected.initiate(undefined, { subscribe: false }),
592592
)
593-
expect(onNewCacheEntry).toHaveBeenCalledTimes(1)
593+
expect(onNewCacheEntry).toHaveBeenCalledOnce()
594594

595595
// will not be called a second time though
596596
await storeRef.store.dispatch(extended.endpoints.injected.initiate(undefined))
597-
expect(onNewCacheEntry).toHaveBeenCalledTimes(1)
597+
expect(onNewCacheEntry).toHaveBeenCalledOnce()
598598
})
599599

600600
test('dispatching a mutation initializer with `track: false` does not start a lifecycle', async () => {
@@ -615,5 +615,5 @@ test('dispatching a mutation initializer with `track: false` does not start a li
615615
expect(onNewCacheEntry).toHaveBeenCalledTimes(0)
616616

617617
await storeRef.store.dispatch(extended.endpoints.injected.initiate(undefined))
618-
expect(onNewCacheEntry).toHaveBeenCalledTimes(1)
618+
expect(onNewCacheEntry).toHaveBeenCalledOnce()
619619
})

packages/toolkit/src/query/tests/polling.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ describe('polling tests', () => {
4545
}),
4646
)
4747

48-
expect(mockBaseQuery).toHaveBeenCalledTimes(1)
48+
expect(mockBaseQuery).toHaveBeenCalledOnce()
4949

5050
storeRef.store.dispatch(api.util.resetApiState())
5151

5252
await delay(30)
5353

54-
expect(mockBaseQuery).toHaveBeenCalledTimes(1)
54+
expect(mockBaseQuery).toHaveBeenCalledOnce()
5555
})
5656

5757
it('replaces polling interval when the subscription options are updated', async () => {

packages/toolkit/src/query/tests/queryLifecycle.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ test('query: will only start lifecycle if query is not skipped due to `condition
438438
const promise = storeRef.store.dispatch(
439439
extended.endpoints.injected.initiate('arg'),
440440
)
441-
expect(onStart).toHaveBeenCalledTimes(1)
441+
expect(onStart).toHaveBeenCalledOnce()
442442
storeRef.store.dispatch(extended.endpoints.injected.initiate('arg'))
443-
expect(onStart).toHaveBeenCalledTimes(1)
443+
expect(onStart).toHaveBeenCalledOnce()
444444
await promise
445445
storeRef.store.dispatch(
446446
extended.endpoints.injected.initiate('arg', { forceRefetch: true }),

packages/toolkit/src/query/tests/retry.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { vi } from 'vitest'
21
import type { BaseQueryFn, FetchBaseQueryError } from '@reduxjs/toolkit/query'
32
import { createApi, retry } from '@reduxjs/toolkit/query'
3+
import { vi } from 'vitest'
44
import { setupApiStore } from '../../tests/utils/helpers'
55

66
beforeEach(() => {
@@ -223,7 +223,7 @@ describe('configuration', () => {
223223

224224
await loopTimers(2)
225225

226-
expect(baseBaseQuery).toHaveBeenCalledTimes(1)
226+
expect(baseBaseQuery).toHaveBeenCalledOnce()
227227
})
228228
test('calling retry.fail(error) will skip retrying and expose the error directly', async () => {
229229
const error = { message: 'banana' }
@@ -255,7 +255,7 @@ describe('configuration', () => {
255255

256256
await loopTimers(2)
257257

258-
expect(baseBaseQuery).toHaveBeenCalledTimes(1)
258+
expect(baseBaseQuery).toHaveBeenCalledOnce()
259259
expect(result.error).toEqual(error)
260260
expect(result).toEqual({
261261
endpointName: 'q1',
@@ -464,6 +464,6 @@ describe('configuration', () => {
464464
storeRef.store.dispatch(api.endpoints.q1.initiate({}))
465465
await loopTimers(2)
466466

467-
expect(baseBaseQuery).toHaveBeenCalledTimes(1)
467+
expect(baseBaseQuery).toHaveBeenCalledOnce()
468468
})
469469
})

packages/toolkit/src/tests/createAsyncThunk.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ describe('conditional skipping of asyncThunks', () => {
586586
const asyncThunk = createAsyncThunk('test', payloadCreator, { condition })
587587
await asyncThunk(arg)(dispatch, getState, extra)
588588

589-
expect(condition).toHaveBeenCalledTimes(1)
589+
expect(condition).toHaveBeenCalledOnce()
590590
expect(condition).toHaveBeenLastCalledWith(
591591
arg,
592592
expect.objectContaining({ getState, extra }),
@@ -597,7 +597,7 @@ describe('conditional skipping of asyncThunks', () => {
597597
const condition = () => true
598598
const asyncThunk = createAsyncThunk('test', payloadCreator, { condition })
599599
const thunkCallPromise = asyncThunk(arg)(dispatch, getState, extra)
600-
expect(dispatch).toHaveBeenCalledTimes(1)
600+
expect(dispatch).toHaveBeenCalledOnce()
601601
await thunkCallPromise
602602
expect(dispatch).toHaveBeenCalledTimes(2)
603603
})
@@ -613,7 +613,7 @@ describe('conditional skipping of asyncThunks', () => {
613613
const condition = () => Promise.reject()
614614
const asyncThunk = createAsyncThunk('test', payloadCreator, { condition })
615615
await asyncThunk(arg)(dispatch, getState, extra)
616-
expect(dispatch).toHaveBeenCalledTimes(1)
616+
expect(dispatch).toHaveBeenCalledOnce()
617617
expect(dispatch).toHaveBeenLastCalledWith(
618618
expect.objectContaining({ type: 'test/rejected' }),
619619
)
@@ -663,7 +663,7 @@ describe('conditional skipping of asyncThunks', () => {
663663
})
664664
await asyncThunk(arg)(dispatch, getState, extra)
665665

666-
expect(dispatch).toHaveBeenCalledTimes(1)
666+
expect(dispatch).toHaveBeenCalledOnce()
667667
expect(dispatch).toHaveBeenLastCalledWith(
668668
expect.objectContaining({
669669
error: {
@@ -871,9 +871,9 @@ test('`condition` will see state changes from a synchronously invoked asyncThunk
871871
})
872872

873873
store.dispatch(asyncThunk({ force: false }))
874-
expect(onStart).toHaveBeenCalledTimes(1)
874+
expect(onStart).toHaveBeenCalledOnce()
875875
store.dispatch(asyncThunk({ force: false }))
876-
expect(onStart).toHaveBeenCalledTimes(1)
876+
expect(onStart).toHaveBeenCalledOnce()
877877
store.dispatch(asyncThunk({ force: true }))
878878
expect(onStart).toHaveBeenCalledTimes(2)
879879
})

packages/toolkit/src/tests/createReducer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('createReducer', () => {
217217
expect(spy).not.toHaveBeenCalled()
218218

219219
const initialState = dummyReducer(undefined, { type: 'dummy' })
220-
expect(spy).toHaveBeenCalledTimes(1)
220+
expect(spy).toHaveBeenCalledOnce()
221221
})
222222
})
223223

0 commit comments

Comments
 (0)