Skip to content

Commit cc3d827

Browse files
committed
use a let for store instead of test context
1 parent 339ec04 commit cc3d827

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

examples/lazy-injection/kitchen-sink/src/features/counter/counterSlice.test.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { AppStore } from "../../app/store"
21
import { makeStore } from "../../app/store"
32
import type { CounterSliceState } from "./counterSlice"
43
import {
@@ -9,20 +8,16 @@ import {
98
selectCount,
109
} from "./counterSlice"
1110

12-
interface LocalTestContext {
13-
store: AppStore
14-
}
11+
describe("counter reducer", it => {
12+
let store = makeStore()
1513

16-
describe<LocalTestContext>("counter reducer", it => {
17-
beforeEach<LocalTestContext>(context => {
14+
beforeEach(() => {
1815
const initialState: CounterSliceState = {
1916
value: 3,
2017
status: "idle",
2118
}
2219

23-
const store = makeStore({ counter: initialState })
24-
25-
context.store = store
20+
store = makeStore({ counter: initialState })
2621
})
2722

2823
it("should handle initial state", () => {
@@ -32,23 +27,23 @@ describe<LocalTestContext>("counter reducer", it => {
3227
})
3328
})
3429

35-
it("should handle increment", ({ store }) => {
30+
it("should handle increment", () => {
3631
expect(selectCount(store.getState())).toBe(3)
3732

3833
store.dispatch(increment())
3934

4035
expect(selectCount(store.getState())).toBe(4)
4136
})
4237

43-
it("should handle decrement", ({ store }) => {
38+
it("should handle decrement", () => {
4439
expect(selectCount(store.getState())).toBe(3)
4540

4641
store.dispatch(decrement())
4742

4843
expect(selectCount(store.getState())).toBe(2)
4944
})
5045

51-
it("should handle incrementByAmount", ({ store }) => {
46+
it("should handle incrementByAmount", () => {
5247
expect(selectCount(store.getState())).toBe(3)
5348

5449
store.dispatch(incrementByAmount(2))

examples/lazy-injection/kitchen-sink/src/features/todos/todoSlice.test.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { nanoid } from "@reduxjs/toolkit"
2-
import type { AppStore } from "../../app/store"
32
import { makeStore } from "../../app/store"
43
import type { Todo } from "./todoSlice"
54
import {
@@ -14,19 +13,14 @@ import {
1413
todoSlice,
1514
} from "./todoSlice"
1615

17-
interface LocalTestContext {
18-
store: AppStore
19-
}
20-
2116
const initialTodo: Todo = { id: nanoid(), title: "Initial todo" }
2217

23-
describe<LocalTestContext>("counter reducer", it => {
24-
beforeEach<LocalTestContext>(context => {
25-
const store = makeStore({
18+
describe("counter reducer", () => {
19+
let store = makeStore()
20+
beforeEach(() => {
21+
store = makeStore({
2622
todo: todoAdapter.setOne(todoAdapter.getInitialState(), initialTodo),
2723
})
28-
29-
context.store = store
3024
})
3125

3226
it("should handle initial state", () => {
@@ -35,7 +29,7 @@ describe<LocalTestContext>("counter reducer", it => {
3529
)
3630
})
3731

38-
it("should handle addTodo", ({ store }) => {
32+
it("should handle addTodo", () => {
3933
expect(selectTodoIds(store.getState())).toStrictEqual([initialTodo.id])
4034

4135
store.dispatch(addTodo({ title: "Second todo!" }))
@@ -48,7 +42,7 @@ describe<LocalTestContext>("counter reducer", it => {
4842
})
4943
})
5044

51-
it("should handle deleteTodo", ({ store }) => {
45+
it("should handle deleteTodo", () => {
5246
expect(selectAllTodos(store.getState())).toStrictEqual([initialTodo])
5347

5448
store.dispatch(deleteTodo(initialTodo.id))

0 commit comments

Comments
 (0)