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.
You should pass a stubClosure to MoyaProvider on instantiation. There are some default ones:
neverStub (default)immediatelyStubdelayedStube.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.
Most helpful comment
You should pass a
stubClosuretoMoyaProvideron instantiation. There are some default ones:neverStub(default)immediatelyStubdelayedStube.g.