Created
April 11, 2021 21:12
-
-
Save TheiOSDude/871060a692c8c8594cfd4868de434ceb to your computer and use it in GitHub Desktop.
NameViewerTests
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_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