Moya: How to use sampleData response for unit tests?

Created on 2 Mar 2017  路  4Comments  路  Source: Moya/Moya

How can I use the sampleData defined in TargetTypes for unit testing (XCTests)?
I tried specifying an endpoint closure, but it still goes to the actual end point and returns that response instead of the sampleData.

Any guidance would be greatly appreciated.

question

Most helpful comment

You should pass a stubClosure to MoyaProvider on instantiation. There are some default ones:

  • neverStub (default)
  • immediatelyStub
  • delayedStub

e.g.

let provider = MoyaProvider<MyApi>(stubClosure: MoyaProvider.immediatelyStub)

All 4 comments

You should pass a stubClosure to MoyaProvider on instantiation. There are some default ones:

  • neverStub (default)
  • immediatelyStub
  • delayedStub

e.g.

let provider = MoyaProvider<MyApi>(stubClosure: MoyaProvider.immediatelyStub)

Aha! That was the missing part from my code. It would be great if this is reflected in the docs, especially here:
https://github.com/Moya/Moya/blob/master/docs/Examples/Basic.md

@sevrazzmatazz Hey, the usage is actually on the docs (here). Any ideas on how we could make this easier to find? 馃

@Moya/contributors Issue #1001 also discusses the difficulty of finding the docs on stub closures. I'm going to close this.

Was this page helpful?
0 / 5 - 0 ratings