Skip to content

Instantly share code, notes, and snippets.

@TheiOSDude
Created April 11, 2021 21:17
Show Gist options
  • Save TheiOSDude/7ee3c86c64e77985c26497047c4363c5 to your computer and use it in GitHub Desktop.
Save TheiOSDude/7ee3c86c64e77985c26497047c4363c5 to your computer and use it in GitHub Desktop.
NameViewerFailure.swift
func test_failure() {
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: 304,
httpVersion: nil,
headerFields: ["Content-Type": "application/json"])!
return (response, data)
}
let nameViewer = NameViewer(apiClient: MockNetworking())
let sucessExpectation = expectation(description: "should not succeed")
let failureExpectation = expectation(description: "should fail")
sucessExpectation.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