Giter VIP home page Giter VIP logo

Comments (4)

daneov avatar daneov commented on May 25, 2024 1

I ended up making sure the Networking instance doesn't deallocate in the tests by retaining the object as follows:

func execute<T>(request: T,
                    mockProvider: MockProvider<T>? = nil) -> NetworkPromise where T: RequestConvertible {
        let networking = Networking<T>(mode: .async, mockProvider: mockProvider)
        return networking.request(request).validate().always({ _ in _ = networking })

Thanks for the help!

from malibu.

vadymmarkov avatar vadymmarkov commented on May 25, 2024

You could make networking an instance var in your test and then inject it to APIFetcher for example.

from malibu.

daneov avatar daneov commented on May 25, 2024

Sorry, due to oversimplifying the real case got lost :)

Here is a gist containing the actual case.

The execute<T>(request: T) -> NetworkPromise is required by the protocol, and relied upon by my services.

If I want to test a service, I thus mock the APIClient in them, and the Networking instance is configured in the APIMockClient, since in the real world, it is also responsible for configuring the Networking's headers and authentication token.

Now, in a real world example this approach works:

    func execute<T>(request: T,
                    mockProvider: MockProvider<T>? = nil) -> NetworkPromise where T: RequestConvertible {
        let networking = Networking<T>(mode: .async, mockProvider: mockProvider)
        networking.configureHeaders()
        networking.configure(token: userManager.accessToken)

        return networking.request(request).validate()

So I am a bit confused here, as the exact same approach is used.

from malibu.

vadymmarkov avatar vadymmarkov commented on May 25, 2024

When I use Malibu I usually keep a reference to Networking class somewhere. In your case it's not easy to find a workaround without changing the code. It would be easier if you had a generic APIMockClient with networking being an instance var, but it doesn't follow func execute<T>(request: T) method from APIClientMethods protocol.

from malibu.

Related Issues (20)

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.