Unable to access toBlocking() in xctest

573 Views Asked by At

I am trying to write test cases and trying to access a method which returns Single object. For this I want to use toBlocking but I am not able to access it and getting following error:

Value of type 'Single<[Property]>' (aka 'PrimitiveSequence>') has no member 'toBlocking'

Following is my code

 do {
        let property = try viewModel.getPropertyList(city: "1530")
            .toBlocking()
            .single()
        XCTAssertNotNil(property)
    } catch {
        XCTFail("Get user settings failed")
    }

Already imported following frameworks:

import RxCocoa   
import RxSwift  
import XCTest
1

There are 1 best solutions below

0
On

You need to import RxBlocking too! if it raises error then you should add RxBlocking to your Test target in your package manager.

For example in Pod you should have something like this in your Pod file :

target 'YourProjectTests' do
    pod 'RxSwift',    '~> 4.0'
    pod 'RxCocoa',    '~> 4.0'
    pod 'RxBlocking', '~> 4.0'
    pod 'RxTest',     '~> 4.0'
end