Skip to content

Instantly share code, notes, and snippets.

@danielCarlosCE
Last active December 26, 2016 17:53
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 danielCarlosCE/25f889e1936b6cc01f346eb863802e6d to your computer and use it in GitHub Desktop.
Save danielCarlosCE/25f889e1936b6cc01f346eb863802e6d to your computer and use it in GitHub Desktop.
override func setUp() {
super.setUp()
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
readerVC = mainStoryboard.instantiateViewController(withIdentifier: "ReaderViewController") as! ReaderViewController
readerVC.dataSource = MockDataSource()
readerVC.codeReader = mockReader
//force the life cycle to be called
let window = UIApplication.shared.delegate!.window!
window!.rootViewController = readerVC
}
func testItFiresRightEventWhenKnownCodeIsRead() {
let exp = expectation(description: "calls didFindCard")
//given
var didFindCardWasCalled = false
readerVC.didFindCard = { _ in
didFindCardWasCalled = true
exp.fulfill()
}
//when
mockReader.completion?("123")
//then
waitForExpectations(timeout: 3) { error in
XCTAssert(didFindCardWasCalled)
XCTAssertNil(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment