Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a didFailProvisionalNavigation observer. #2620

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions RxCocoa/iOS/WKWebView+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ extension Reactive where Base: WKWebView {
)
}
}

public var didFailProvisionalNavigation: Observable<(WKNavigation, Error)> {
navigationDelegate
.methodInvoked(#selector(WKNavigationDelegate.webView(_:didFailProvisionalNavigation:withError:)))
.map { a in
(
try castOrThrow(WKNavigation.self,a[1]),
try castOrThrow(Error.self, a[2])
)
}
}
}

#endif
16 changes: 16 additions & 0 deletions Tests/RxCocoaTests/WKWebView+RxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ final class WKWebViewTests: RxTest {
XCTAssertEqual(expectedError, error as? MockError)
subscription.dispose()
}

func testdidFailProvisionalNavigation() {
let expectedNavigation = SafeWKNavigation()
let expexctedError = MockError.error("Something went wrong!")
let webView = WKWebView(frame: .zero)
var navigation: WKNavigation?
var error: Error?
let subscription = webView.rx.didFailProvisionalNavigation.subscribe { (nav, err) in
navigation = nav
error = err
}
webView.navigationDelegate!.webView?(webView, didFailProvisionalNavigation: expectedNavigation, withError:expexctedError)
XCTAssertEqual(expectedNavigation, navigation)
XCTAssertEqual(expexctedError, error as? MockError)
subscription.dispose()
}
}

// MARK: - Test Helpers
Expand Down