|
43 | 43 | /// struct CounterState {
|
44 | 44 | /// var count = 0
|
45 | 45 | /// }
|
46 |
| - /// |
47 | 46 | /// enum CounterAction: Equatable {
|
48 | 47 | /// case decrementButtonTapped
|
49 | 48 | /// case incrementButtonTapped
|
|
68 | 67 | /// class CounterTests: XCTestCase {
|
69 | 68 | /// func testCounter() {
|
70 | 69 | /// let store = TestStore(
|
71 |
| - /// initialState: .init(count: 0), // GIVEN counter state of 0 |
| 70 | + /// initialState: .init(count: 0), // Given a counter state of 0 |
72 | 71 | /// reducer: counterReducer,
|
73 | 72 | /// environment: ()
|
74 | 73 | /// )
|
75 |
| - /// store.send(.incrementButtonTapped) { // WHEN the increment button is tapped |
76 |
| - /// $0.count = 1 // THEN the count should be 1 |
| 74 | + /// store.send(.incrementButtonTapped) { // When the increment button is tapped |
| 75 | + /// $0.count = 1 // Then the count should be 1 |
77 | 76 | /// }
|
78 | 77 | /// }
|
79 | 78 | /// }
|
|
84 | 83 | /// to match the state after the action was sent. In this case the `count` field changes to `1`.
|
85 | 84 | ///
|
86 | 85 | /// For a more complex example, consider the following bare-bones search feature that uses the
|
87 |
| - /// ``Effect/debounce(id:for:scheduler:)`` operator to wait for the user to stop typing |
88 |
| - /// before making a network request: |
| 86 | + /// ``Effect/debounce(id:for:scheduler:)-76yye`` operator to wait for the user to stop |
| 87 | + /// typing before making a network request: |
89 | 88 | ///
|
90 | 89 | /// ```swift
|
91 | 90 | /// struct SearchState: Equatable {
|
|
176 | 175 | private var inFlightEffects: Set<LongLivingEffect> = []
|
177 | 176 | var receivedActions: [(action: Action, state: State)] = []
|
178 | 177 | private let reducer: Reducer<State, Action, Environment>
|
179 |
| - private var snapshotState: State |
| 178 | + private var state: State |
180 | 179 | private var store: Store<State, TestAction>!
|
181 | 180 | private let toLocalState: (State) -> LocalState
|
182 | 181 |
|
|
194 | 193 | self.fromLocalAction = fromLocalAction
|
195 | 194 | self.line = line
|
196 | 195 | self.reducer = reducer
|
197 |
| - self.snapshotState = initialState |
| 196 | + self.state = initialState |
198 | 197 | self.toLocalState = toLocalState
|
199 | 198 |
|
200 | 199 | self.store = Store(
|
|
204 | 203 | switch action.origin {
|
205 | 204 | case let .send(localAction):
|
206 | 205 | effects = self.reducer.run(&state, self.fromLocalAction(localAction), self.environment)
|
207 |
| - self.snapshotState = state |
| 206 | + self.state = state |
208 | 207 |
|
209 | 208 | case let .receive(action):
|
210 | 209 | effects = self.reducer.run(&state, action, self.environment)
|
|
352 | 351 | file: file, line: line
|
353 | 352 | )
|
354 | 353 | }
|
355 |
| - var expectedState = self.toLocalState(self.snapshotState) |
| 354 | + var expectedState = self.toLocalState(self.state) |
356 | 355 | self.store.send(.init(origin: .send(action), file: file, line: line))
|
357 | 356 | do {
|
358 | 357 | try self.expectedStateShouldChange(
|
|
366 | 365 | }
|
367 | 366 | self.expectedStateShouldMatch(
|
368 | 367 | expected: expectedState,
|
369 |
| - actual: self.toLocalState(self.snapshotState), |
| 368 | + actual: self.toLocalState(self.state), |
370 | 369 | file: file,
|
371 | 370 | line: line
|
372 | 371 | )
|
|
465 | 464 | file: file, line: line
|
466 | 465 | )
|
467 | 466 | }
|
468 |
| - var expectedState = self.toLocalState(self.snapshotState) |
| 467 | + var expectedState = self.toLocalState(self.state) |
469 | 468 | do {
|
470 | 469 | try self.expectedStateShouldChange(
|
471 | 470 | expected: &expectedState,
|
|
482 | 481 | file: file,
|
483 | 482 | line: line
|
484 | 483 | )
|
485 |
| - snapshotState = state |
| 484 | + self.state = state |
486 | 485 | if "\(self.file)" == "\(file)" {
|
487 | 486 | self.line = line
|
488 | 487 | }
|
|
0 commit comments