Skip to content

Clean up skipInFlightEffects and write test on beahvior. #2057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Sources/ComposableArchitecture/TestStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2114,10 +2114,6 @@ extension TestStore {
file: file,
line: line
)

for effect in self.reducer.inFlightEffects {
_ = EffectPublisher<Never, Never>.cancel(id: effect.id).sink { _ in }
}
self.reducer.inFlightEffects = []
}

Expand Down
27 changes: 27 additions & 0 deletions Tests/ComposableArchitectureTests/TestStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,33 @@ final class TestStoreTests: BaseTCATestCase {
$0.date = now
}
}

func testEffectEmitAfterSkipInFlightEffects() async {
let mainQueue = DispatchQueue.test
enum Action: Equatable { case tap, response }
let store = TestStore(
initialState: 0,
reducer: Reduce<Int, Action> { state, action in
switch action {
case .tap:
return .run { send in
try await mainQueue.sleep(for: .seconds(1))
await send(.response)
}
case .response:
state = 42
return .none
}
}
)

await store.send(.tap)
await store.skipInFlightEffects()
await mainQueue.advance(by: .seconds(1))
await store.receive(.response) {
$0 = 42
}
}
}

private struct Client: DependencyKey {
Expand Down