Skip to content

Commit 12c0ec2

Browse files
committed
Add tests for Thunk redispatching raw
1 parent be7de5a commit 12c0ec2

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

Tests/RecombineTests/MiddlewareFakes.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,12 @@ let stateAccessingMiddleware = Middleware<TestFakes.StringTest.State, TestFakes.
2626
return [action]
2727
}
2828

29-
let firstThunk = Thunk<TestFakes.StringTest.State, TestFakes.SetAction, TestFakes.SetAction> { _, action -> Just<ActionStrata<TestFakes.SetAction, TestFakes.SetAction>> in
29+
let thunk = Thunk<TestFakes.StringTest.State, TestFakes.ThunkRawAction, TestFakes.SetAction> { _, action -> Just<ActionStrata<TestFakes.ThunkRawAction, TestFakes.SetAction>> in
3030
switch action {
31-
case let .string(value):
32-
return Just(.refined(.string(value + " First Middleware")))
33-
default:
34-
return Just(.refined(action))
35-
}
36-
}
37-
38-
let secondThunk = Thunk<TestFakes.StringTest.State, TestFakes.SetAction, TestFakes.SetAction> { _, action -> Just<ActionStrata<TestFakes.SetAction, TestFakes.SetAction>> in
39-
switch action {
40-
case let .string(value):
41-
return Just(.refined(.string(value + " Second Middleware")))
42-
default:
43-
return Just(.refined(action))
31+
case let .first(value):
32+
return Just(.raw(.second(value + " First Thunk")))
33+
case let .second(value):
34+
return Just(.refined(.string(value + " Second Thunk")))
4435
}
4536
}
4637

Tests/RecombineTests/StoreMiddlewareTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ class StoreMiddlewareTests: XCTestCase {
2929
state: TestFakes.StringTest.State(),
3030
reducer: TestFakes.StringTest.reducer,
3131
middleware: .init(),
32-
thunk: firstThunk,
32+
thunk: thunk,
3333
publishOn: ImmediateScheduler.shared
3434
)
35-
let action = TestFakes.SetAction.string("OK")
36-
store.dispatch(raw: action)
35+
store.dispatch(raw: .first("OK"))
3736

38-
XCTAssertEqual(store.state.value, "OK First Middleware")
37+
XCTAssertEqual(store.state.value, "OK First Thunk Second Thunk")
3938
}
4039

4140
/**

Tests/RecombineTests/TestFakes.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ extension TestFakes {
4848
}
4949
}
5050

51+
extension TestFakes {
52+
enum ThunkRawAction {
53+
case first(String)
54+
case second(String)
55+
}
56+
}
57+
5158
extension TestFakes {
5259
enum StringTest {
5360
struct State: Equatable {

0 commit comments

Comments
 (0)