Created
June 18, 2020 14:43
-
-
Save stevencurtis/f76811cb8719d999e251fbf956d23e52 to your computer and use it in GitHub Desktop.
testViewControllerSuccess
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 testViewControllerSuccess() { | |
let expect = expectation(description: #function) | |
let viewController = ViewController() | |
let data = jsonString.data(using: .utf8) | |
URLProtocolMock.requestHandler = { request in | |
let response = HTTPURLResponse(url: URL(fileURLWithPath: ""), statusCode: 200, httpVersion: nil, headerFields: nil)! | |
return (response, data) | |
} | |
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 | |
let expectedModel = jsonString.data(using: .utf8) | |
switch response { | |
case .failure: | |
XCTFail() | |
case .success(let data): | |
XCTAssertEqual(expectedModel, data) | |
expect.fulfill() | |
} | |
}) | |
wait(for: [expect], timeout: 1.0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment