I'm trying to write some tests for my application, that uses rxSwift. In particular, I'd like to test, writing unit tests, a webview. I'm using RxWebKit to get observables over some properties like navigationCompleted or NavigationFailed and so on.
For example: webView.rx.didFailNavigation.asDriver()
. These observables are given as input to my viewModel.
But i'm not sure how to write these tests to simulate, for example, a failed navigation and so an emission of this kind of observable.
In the specific case, i want to simulate a Driver<(webView: WKWebView, navigation: WKNavigation, error: Error)>
(that is the same type of the one associated to webView.rx.didFailNavigation.asDriver()
).
I understood that to simulate the emission i need to create a scheduler and call the createHotObservable
method, but what have I to pass to Recorderd.next(150, element)
as element in the specific case to simulate the fail of the webview?
can someone give me a simple example?
How to test a WKWebView using RxWebKit?
345 Views Asked by Giuseppe Pennisi At
1
This is a bit too general question so I'll give a more general answer:
You need to look into testing with RxSwift, either using:
for example:
For example, here's a good point to start:
http://rx-marin.com/post/rxblocking-part1/