Skip to content

Instantly share code, notes, and snippets.

@TheiOSDude
Created April 11, 2021 21:12
Show Gist options
  • Save TheiOSDude/871060a692c8c8594cfd4868de434ceb to your computer and use it in GitHub Desktop.
Save TheiOSDude/871060a692c8c8594cfd4868de434ceb to your computer and use it in GitHub Desktop.
NameViewerTests
func test_success() {
let response =
"""
[
{
"firstName": "Lee",
"lastName": "Burrows"
},
{
"firstName": "Dolly",
"lastName": "Burrows"
}
]
"""
let data = response.data(using: .utf8)!
MockURLProtocol.error = nil
MockURLProtocol.requestHandler = { request in
let response = HTTPURLResponse(url: URL(string: "https://theiosdude.api.com/test")!,
statusCode: 200,
httpVersion: nil,
headerFields: ["Content-Type": "application/json"])!
return (response, data)
}
let nameViewer = NameViewer(apiClient: MockNetworking())
let sucessExpectation = expectation(description: "should succeed")
let failureExpectation = expectation(description: "should not fail")
failureExpectation.isInverted = true
nameViewer.didUpdate = {
sucessExpectation.fulfill()
}
nameViewer.didError = {
failureExpectation.fulfill()
}
nameViewer.getNames()
wait(for: [sucessExpectation, failureExpectation], timeout: 5.0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment