Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created June 18, 2020 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/f76811cb8719d999e251fbf956d23e52 to your computer and use it in GitHub Desktop.
Save stevencurtis/f76811cb8719d999e251fbf956d23e52 to your computer and use it in GitHub Desktop.
testViewControllerSuccess
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