Created
April 11, 2021 21:17
-
-
Save TheiOSDude/7ee3c86c64e77985c26497047c4363c5 to your computer and use it in GitHub Desktop.
NameViewerFailure.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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