Giter Site home page Giter Site logo

Comments (11)

tgrapperon avatar tgrapperon commented on May 19, 2024 1

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.

arietis avatar arietis commented on May 19, 2024 1

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.

tgrapperon avatar tgrapperon commented on May 19, 2024 1

@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.

tgrapperon avatar tgrapperon commented on May 19, 2024 1

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.

tgrapperon avatar tgrapperon commented on May 19, 2024

Great! I'll close the issue then. Feel free to reopen it if the problem is back!

from swift-dependencies-additions.

arietis avatar arietis commented on May 19, 2024

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.

tgrapperon avatar tgrapperon commented on May 19, 2024

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.

JacksonUtsch avatar JacksonUtsch commented on May 19, 2024

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.

tgrapperon avatar tgrapperon commented on May 19, 2024

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.

JacksonUtsch avatar JacksonUtsch commented on May 19, 2024

It doesn't look like I have static linking. Here is a demo of the issue. 🤔

from swift-dependencies-additions.

JacksonUtsch avatar JacksonUtsch commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.