Dependency in test uses live value when used with combine in reducer instead of mock value specified in test #1870
Replies: 1 comment 4 replies
-
Hi @dvosscricut, this is not a bug with the library, but rather an intended consequence of using escaping closures. The use of schedulerClient.operation.schedule {
let values = testGetValuesClient.getValues()
completion(.success(.scheduledAction(values)))
} …is using an This is happening because dependencies are built on top of One way to fix this is to not using unstructured tools such as If it's not possible to do that, then there is a tool you can use to propagate dependencies through to an escaping closure, and it's called return .future { completion in
withEscapedDependencies { continuation in
schedulerClient.operation.schedule {
continuation.yield {
let values = testGetValuesClient.getValues()
completion(.success(.scheduledAction(values)))
}
}
}
} With that change your test will pass as you expect. Because this is not an issue with the library I am going to convert it to a discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Dependency in test uses live value when used with combine in reducer instead of mock value specified in test
Checklist
main
branch of this package.Expected behavior
bug is in testDemoFeature even though testGetValuesClient is assigned to return mockValues in unit test, it's actually using liveValue instead! So instead of succeeding with mock values of [1776, 1778, 1896], it fails with live value of [42]
Actual behavior
bug is in testDemoFeature even though testGetValuesClient is assigned to return mockValues in unit test, it's actually using liveValue instead! So instead of succeeding with mock values of [1776, 1778, 1896], it fails with live value of [42]
Steps to reproduce
TcaDependencyTestBugV0.50.0.zip
run
testDemoFeature
unit test and observe test failure when it should succeedThe Composable Architecture version information
0.50.0
Destination operating system
iOS 16.2 (also occurs with project target iOS 15.0)
Xcode version information
14.2
Swift Compiler version information
Beta Was this translation helpful? Give feedback.
All reactions