@@ -236,21 +236,22 @@ class StoreTests: XCTestCase {
236
236
wait ( for: [ VoidTestEffects . expectation] , timeout: 5 )
237
237
}
238
238
239
- /// Can we get all state changes in a `MockStore `?
240
- func testMockStoreStateChanges ( ) {
239
+ /// Does the `Store` dispatch actions when it subscribes to a `Publisher `?
240
+ func testSubscribing ( ) {
241
241
// Given
242
- let mockStore = MockStore ( initialState: TestState ( type: . initial, lastAction: nil ) )
242
+ let subject = PassthroughSubject < Action , Never > ( )
243
+ let interceptor = TestInterceptor < TestState > ( )
244
+ let store = Store ( initialState: TestState ( type: . initial) )
245
+ store. register ( interceptor: interceptor)
246
+ subject. subscribe ( store)
247
+ XCTAssertEqual ( interceptor. stateChanges. count, 0 )
243
248
let action = TestAction ( )
244
- let modifiedState = TestState ( type: . modified, lastAction: " Set State " )
245
249
// When
246
- mockStore . dispatch ( action : action)
247
- mockStore . setState ( newState : modifiedState )
250
+ subject . send ( action)
251
+ subject . send ( completion : . finished )
248
252
// Then
249
- XCTAssertEqual ( mockStore. stateChanges. count, 2 )
250
- XCTAssertEqual ( mockStore. stateChanges [ 0 ] . action as! TestAction , action)
251
- let setStateAction = mockStore. stateChanges [ 1 ] . action as! AnonymousAction < TestState >
252
- XCTAssertEqual ( setStateAction. id, " Set State " )
253
- XCTAssertEqual ( mockStore. stateChanges [ 1 ] . newState, modifiedState)
253
+ XCTAssertEqual ( interceptor. stateChanges. count, 1 )
254
+ XCTAssertEqual ( interceptor. stateChanges [ 0 ] . action as! TestAction , action)
254
255
}
255
256
}
256
257
0 commit comments