Skip to content

Commit a47ce6a

Browse files
committed
Fix no-empty related problems
1 parent 0ba88b5 commit a47ce6a

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import {
33
configureStore,
44
createAsyncThunk,
55
createReducer,
6-
unwrapResult,
76
miniSerializeError,
7+
unwrapResult,
88
} from '@reduxjs/toolkit'
99
import { vi } from 'vitest'
1010

11+
import { delay } from '@internal/utils'
1112
import {
1213
createConsole,
1314
getLog,
1415
mockConsole,
1516
} from 'console-testing-library/pure'
16-
import { delay } from '@internal/utils'
1717

1818
declare global {
1919
interface Window {
@@ -131,7 +131,9 @@ describe('createAsyncThunk', () => {
131131

132132
try {
133133
await thunkFunction(dispatch, () => {}, undefined)
134-
} catch (e) {}
134+
} catch (e) {
135+
/* empty */
136+
}
135137

136138
expect(dispatch).toHaveBeenNthCalledWith(
137139
1,
@@ -167,7 +169,9 @@ describe('createAsyncThunk', () => {
167169

168170
try {
169171
await thunkFunction(dispatch, () => {}, undefined)
170-
} catch (e) {}
172+
} catch (e) {
173+
/* empty */
174+
}
171175

172176
expect(dispatch).toHaveBeenNthCalledWith(
173177
1,
@@ -206,7 +210,9 @@ describe('createAsyncThunk', () => {
206210

207211
try {
208212
await thunkFunction(dispatch, () => {}, undefined)
209-
} catch (e) {}
213+
} catch (e) {
214+
/* empty */
215+
}
210216

211217
expect(dispatch).toHaveBeenNthCalledWith(
212218
1,
@@ -251,7 +257,9 @@ describe('createAsyncThunk', () => {
251257

252258
try {
253259
await thunkFunction(dispatch, () => {}, undefined)
254-
} catch (e) {}
260+
} catch (e) {
261+
/* empty */
262+
}
255263

256264
expect(dispatch).toHaveBeenNthCalledWith(
257265
1,
@@ -296,7 +304,9 @@ describe('createAsyncThunk', () => {
296304

297305
try {
298306
await thunkFunction(dispatch, () => {}, undefined)
299-
} catch (e) {}
307+
} catch (e) {
308+
/* empty */
309+
}
300310

301311
expect(dispatch).toHaveBeenNthCalledWith(
302312
1,
@@ -350,7 +360,9 @@ describe('createAsyncThunk', () => {
350360

351361
try {
352362
await thunkFunction(dispatch, () => {}, undefined)
353-
} catch (e) {}
363+
} catch (e) {
364+
/* empty */
365+
}
354366

355367
expect(dispatch).toHaveBeenNthCalledWith(
356368
1,
@@ -640,7 +652,9 @@ describe('conditional skipping of asyncThunks', () => {
640652
const thunkPromise = asyncThunk(arg)(dispatch, getState, extra)
641653
thunkPromise.abort()
642654
await thunkPromise
643-
} catch (err) {}
655+
} catch (err) {
656+
/* empty */
657+
}
644658
expect(dispatch).toHaveBeenCalledTimes(0)
645659
})
646660

@@ -969,6 +983,7 @@ describe('meta', () => {
969983
})
970984

971985
if (ret.meta.requestStatus === 'rejected' && ret.meta.rejectedWithValue) {
986+
/* empty */
972987
} else {
973988
// could be caused by a `throw`, `abort()` or `condition` - no `rejectedMeta` in that case
974989
// @ts-expect-error

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {
2-
Store,
3-
MiddlewareAPI,
42
ImmutableStateInvariantMiddlewareOptions,
53
Middleware,
4+
MiddlewareAPI,
5+
Store,
66
} from '@reduxjs/toolkit'
77
import {
88
createImmutableStateInvariantMiddleware,
@@ -11,9 +11,9 @@ import {
1111

1212
import { trackForMutations } from '@internal/immutableStateInvariantMiddleware'
1313
import {
14-
mockConsole,
1514
createConsole,
1615
getLog,
16+
mockConsole,
1717
} from 'console-testing-library/pure'
1818

1919
type MWNext = Parameters<ReturnType<Middleware>>[0]
@@ -161,7 +161,9 @@ describe('createImmutableStateInvariantMiddleware', () => {
161161
it('Should not print a warning if "next" takes too long', () => {
162162
const next: MWNext = (action) => {
163163
const started = Date.now()
164-
while (Date.now() - started < 8) {}
164+
while (Date.now() - started < 8) {
165+
/* empty */
166+
}
165167
return action
166168
}
167169

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ describe('serializableStateInvariantMiddleware', () => {
110110
store.dispatch(dispatchedAction)
111111

112112
expect(getLog().log).toMatchInlineSnapshot(`
113-
"A non-serializable value was detected in an action, in the path: \`payload\`. Value: Symbol(SOME_CONSTANT)
113+
"A non-serializable value was detected in an action, in the path: \`payload\`. Value: Symbol(SOME_CONSTANT)
114114
Take a look at the logic that dispatched this action: Object {
115115
"payload": Symbol(SOME_CONSTANT),
116116
"type": "an-action",
117-
}
118-
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
117+
}
118+
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
119119
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"
120120
`)
121121
})
@@ -154,7 +154,7 @@ describe('serializableStateInvariantMiddleware', () => {
154154
store.dispatch({ type: ACTION_TYPE })
155155

156156
expect(getLog().log).toMatchInlineSnapshot(`
157-
"A non-serializable value was detected in the state, in the path: \`testSlice.a\`. Value: Map {}
157+
"A non-serializable value was detected in the state, in the path: \`testSlice.a\`. Value: Map {}
158158
Take a look at the reducer(s) handling this action type: TEST_ACTION.
159159
(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)"
160160
`)
@@ -215,7 +215,7 @@ describe('serializableStateInvariantMiddleware', () => {
215215

216216
// since default options are used, the `entries` function in `serializableObject` will cause the error
217217
expect(getLog().log).toMatchInlineSnapshot(`
218-
"A non-serializable value was detected in the state, in the path: \`testSlice.a.entries\`. Value: [Function entries]
218+
"A non-serializable value was detected in the state, in the path: \`testSlice.a.entries\`. Value: [Function entries]
219219
Take a look at the reducer(s) handling this action type: TEST_ACTION.
220220
(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)"
221221
`)
@@ -262,7 +262,7 @@ describe('serializableStateInvariantMiddleware', () => {
262262

263263
// error reported is from a nested class instance, rather than the `entries` function `serializableObject`
264264
expect(getLog().log).toMatchInlineSnapshot(`
265-
"A non-serializable value was detected in the state, in the path: \`testSlice.a.third.bad-map-instance\`. Value: Map {}
265+
"A non-serializable value was detected in the state, in the path: \`testSlice.a.third.bad-map-instance\`. Value: Map {}
266266
Take a look at the reducer(s) handling this action type: TEST_ACTION.
267267
(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)"
268268
`)
@@ -367,14 +367,14 @@ describe('serializableStateInvariantMiddleware', () => {
367367
}).dispatch({ type: 'test', meta: { arg: nonSerializableValue } })
368368

369369
expect(getLog().log).toMatchInlineSnapshot(`
370-
"A non-serializable value was detected in an action, in the path: \`meta.arg\`. Value: Map {}
370+
"A non-serializable value was detected in an action, in the path: \`meta.arg\`. Value: Map {}
371371
Take a look at the logic that dispatched this action: Object {
372372
"meta": Object {
373373
"arg": Map {},
374374
},
375375
"type": "test",
376-
}
377-
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
376+
}
377+
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
378378
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)"
379379
`)
380380
})
@@ -499,7 +499,7 @@ describe('serializableStateInvariantMiddleware', () => {
499499

500500
// testSlice.b.d was not covered in ignoredPaths, so will still log the error
501501
expect(getLog().log).toMatchInlineSnapshot(`
502-
"A non-serializable value was detected in the state, in the path: \`testSlice.b.d\`. Value: Map {}
502+
"A non-serializable value was detected in the state, in the path: \`testSlice.b.d\`. Value: Map {}
503503
Take a look at the reducer(s) handling this action type: TEST_ACTION.
504504
(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)"
505505
`)
@@ -587,7 +587,9 @@ describe('serializableStateInvariantMiddleware', () => {
587587
it('Should not print a warning if "reducer" takes too long', () => {
588588
const reducer: Reducer = (state = 42, action) => {
589589
const started = Date.now()
590-
while (Date.now() - started < 8) {}
590+
while (Date.now() - started < 8) {
591+
/* empty */
592+
}
591593
return state
592594
}
593595

0 commit comments

Comments
 (0)