-
I know that it sounds a bad and non-clean idea, but what I want to test is the error handling of a list refreshing logic with the below steps:
As both steps are using the same logic (through the same dependency, let's call it
I guess I should rather change my code to handle this differently, so I'm also open to receive any kind of feedback for changing this solution to a more testable implementation, but if there's anyway to change the value after init, that'd be great! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @agrabz, you can simply use //WHEN
//would be nice if I could change the value of DataFetcher to MockDataFetcherWithError() before this line.
await withDependencies {
$0.dataFetch = MockDataFetcherWithError()
} operation: {
let task = Task { await sut.handleAsyncEvent(.didPullToRefresh) } //calls DataFetcher.fetchList(), should fail to test error handling logic
await Task.yield()
//THEN
XCTAssert(sut.isListRefreshing == true)
await task.value
XCTAssert(sut.isListRefreshing == false)
XCTAssert(sut.isListInError == true)
} |
Beta Was this translation helpful? Give feedback.
Hi @agrabz, you can simply use
withDependencies
again to alter the dependency environment for a well-defined scope: