Skip to content

Commit 343bf2a

Browse files
committed
Added testStorePublisherSubscriptionOrder() ViewStore test.
1 parent 5658dd0 commit 343bf2a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Tests/ComposableArchitectureTests/ViewStoreTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ final class ViewStoreTests: XCTestCase {
144144
XCTAssertEqual(results, [0, 1])
145145
}
146146

147+
func testStorePublisherSubscriptionOrder() {
148+
let reducer = Reducer<Int, Void, Void> { count, _, _ in
149+
count += 1
150+
return .none
151+
}
152+
let store = Store(initialState: 0, reducer: reducer, environment: ())
153+
let viewStore = ViewStore(store)
154+
155+
var results: [Int] = []
156+
157+
viewStore.produced.producer
158+
.startWithValues { _ in results.append(0) }
159+
160+
viewStore.produced.producer
161+
.startWithValues { _ in results.append(1) }
162+
163+
viewStore.produced.producer
164+
.startWithValues { _ in results.append(2) }
165+
166+
XCTAssertEqual(results, [0, 1, 2])
167+
168+
for _ in 0 ..< 9 {
169+
viewStore.send(())
170+
}
171+
172+
XCTAssertEqual(results, Array(repeating: [0, 1, 2], count: 10).flatMap { $0 })
173+
}
174+
147175
#if compiler(>=5.5) && canImport(_Concurrency)
148176
func testSendWhile() {
149177
guard #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) else { return }

0 commit comments

Comments
 (0)