Comments (11)
Hey @arietis! This is weird indeed. My guess is that there is an escaping closure somewhere (in snapshot testing or in your own code) and the dependencies are reset. You can find more information about this phenomenon in the documentation. In your case, withEscapedDependencies
could help, but I'm not sure how to pass the escaped dependencies up to where it is used. Could you post a little more about View
's internals? Are you using a StateObject
?
from swift-dependencies-additions.
Thanks! I have extracted the snapshotting code out of the closure and it seems to work without failures so far. Will see if it will randomly fail again or not.
from swift-dependencies-additions.
@JacksonUtsch, if you use the trailing closure to set your dependencies, it works:
let store = TestStore(
initialState: ExampleFeature.State(),
reducer: ExampleFeature()
) {
$0.userDefaults = .ephemeral()
}
This is because this dependency fails as soon as you touch its test value, even if you don't call any endpoint. I did it like that because I was lazy and I didn't want to reimplement a complete failing one! I'll try to improve the situation soon.
from swift-dependencies-additions.
The trailing closure wraps everything internally in a withDependencies
. This is the reducer modifier that is triggering the failure, but the value is already implemented when using the closure, so everything is fine then.
But this is rather a limitation of this specific dependency than a problem with the modifier.
from swift-dependencies-additions.
Great! I'll close the issue then. Feel free to reopen it if the problem is back!
from swift-dependencies-additions.
The root problem was similar to this one, I just need to prevent the app from loading in tests. pointfreeco/swift-dependencies#37
from swift-dependencies-additions.
Ah indeed, I missed this possibility! This behavior is extremely annoying. Maybe there are ways to improve its diagnostic because you're not the first, and definitely not the last to trip on it.
Thanks for the follow-up!
from swift-dependencies-additions.
Hmm, I'm getting this same error even with the use of if !_XCTIsTesting {
. I'll look to reproduce this in an isolated project.
It looks like the error occurs when I override the dependency in testing. I was able to reproduce this in a separate project.
import ComposableArchitecture
import XCTest
@testable import ExampleFeature
final class ExampleFeatureTests: XCTestCase {
@MainActor
func testExample() async {
let store = TestStore(
initialState: ExampleFeature.State(),
reducer: ExampleFeature()
.dependency(\.userDefaults, .init(suitename: "test")!)
)
await store.send(.test)
}
}
from swift-dependencies-additions.
Hey @JacksonUtsch! Make sure that you're not linking your test target with Dependencies. See testing section's last paragraph in the doc (on mobile right now)
from swift-dependencies-additions.
It doesn't look like I have static linking. Here is a demo of the issue. 🤔
from swift-dependencies-additions.
Interesting.. I'm not sure how that is achieved when the dependency is overwritten. I'm guessing dependencies are iterated through internally in the TestStore or in Dependencies? And so the logic in result is different where you override.. 🤷
from swift-dependencies-additions.
Related Issues (16)
- Additions suggestion/request HOT 1
- `UserDefaults.Dependency.previewValue` leaks to other `withDependencies`'s? HOT 2
- @Dependency.AppStorage does not work when used with SwiftUI picker HOT 1
- Improve `Logger`'s behavior when testing.
- Lightweight persistence on disk (alternative to the beast that is CoreData) dependency?
- `_CoreDataDependency` doesn't update its `Fetched` item. HOT 3
- Add dependency for `CLLocationManager` HOT 1
- Add ergonomic location dependency HOT 1
- Latest version is incompatible with version 1.0.0 of swift-dependencies HOT 1
- Logger logs in Xcode, but not in iTerm when executableTarget is run from CLI.
- Overriding dependencies on @FunctionProxy's fail when they accept a parameter
- Current state of documentation? HOT 1
- TCA 1.2.0 compatibility HOT 1
- Mutation of captured var 'valueDidChange' in concurrently-executing code HOT 1
- Apple Privacy manifest files HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-dependencies-additions.