Created
June 18, 2020 14:59
-
-
Save stevencurtis/2fa2364ada59cfe1c49e36d2c2c2e1b2 to your computer and use it in GitHub Desktop.
testViewControllerFailure
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 testViewControllerFailure() { | |
let expect = expectation(description: #function) | |
let viewController = ViewController() | |
URLProtocolMock.requestHandler = { request in | |
throw NSError.init(domain: "", code: 400, userInfo: [:]) | |
} | |
let configuration = URLSessionConfiguration.af.default | |
configuration.protocolClasses = [URLProtocolMock.self] + (configuration.protocolClasses ?? []) | |
let session = Session(configuration: configuration) | |
let networkManager = NetworkManager( | |
session: session, | |
router: JSONPlaceHolderAPIAction.getToDo(id: 2)) | |
viewController.downloadData(networkManager, completion: { response in | |
switch response { | |
case .failure(let error): | |
XCTAssertNotNil(error) | |
expect.fulfill() | |
case .success: | |
XCTFail() | |
} | |
}) | |
wait(for: [expect], timeout: 1.0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment