Skip to content
Phi Mage edited this page Nov 28, 2015 · 3 revisions

Create a simple unit test

Writing Tests of Asynchronous Operations

func testSomething() {
    let url: NSURL = // ...
    let expectation = self.expectationWithDescription("description")
    Erik.visitURL(url) { (obj, err) -> Void in
        if let error = err {
           XCTFail("\(error)")
        }
        else if let document = obj {
           if /* check something into doc */ {
              expectation.fulfill()
           }
        }
    }
    self.waitForExpectationsWithTimeout(20, handler: { error in
        XCTAssertNil(error, "Oh, we got timeout")
    })
}          

Advanced features

if let engine = Erik.sharedInstance.layoutEngine as? WebKitLayoutEngine {
    let webView: WKWebView = engine.webView
    // add WKUserScript
    // add WKScriptMessageHandler
    // set a WKNavigationDelegate
}

Sample

OAuthSwift : fill connexion information, submit form then authrorize and finally handle callback redirection into WKNavigationDelegate

Clone this wiki locally