Skip to content

Commit f650bcb

Browse files
committed
Add runtime tests for createDraftSafeSelector.withTypes
1 parent 24ff839 commit f650bcb

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { createDraftSafeSelector } from '@reduxjs/toolkit'
2+
3+
interface Todo {
4+
id: number
5+
completed: boolean
6+
}
7+
8+
interface Alert {
9+
id: number
10+
read: boolean
11+
}
12+
13+
interface RootState {
14+
todos: Todo[]
15+
alerts: Alert[]
16+
}
17+
18+
const rootState: RootState = {
19+
todos: [
20+
{ id: 0, completed: false },
21+
{ id: 1, completed: false },
22+
],
23+
alerts: [
24+
{ id: 0, read: false },
25+
{ id: 1, read: false },
26+
],
27+
}
28+
29+
describe(createDraftSafeSelector.withTypes, () => {
30+
const createTypedDraftSafeSelector =
31+
createDraftSafeSelector.withTypes<RootState>()
32+
33+
test('should return createDraftSafeSelector', () => {
34+
expect(createTypedDraftSafeSelector.withTypes).toEqual(expect.any(Function))
35+
36+
expect(createTypedDraftSafeSelector.withTypes().withTypes).toEqual(
37+
expect.any(Function)
38+
)
39+
40+
expect(createTypedDraftSafeSelector).toBe(createDraftSafeSelector)
41+
42+
const selectTodoIds = createTypedDraftSafeSelector(
43+
[(state) => state.todos],
44+
(todos) => todos.map(({ id }) => id)
45+
)
46+
47+
expect(selectTodoIds(rootState)).to.be.an('array').that.is.not.empty
48+
})
49+
})

0 commit comments

Comments
 (0)