Chapter23 _Adding a View Model test, page 392

let emitted = try! loggedIn.take(3).toBlocking(timeout: 1).toArray()
XCTAssertEqual(emitted[0].element, true)
XCTAssertEqual(emitted[1].element, false)
XCTAssertTrue(emitted[2].isCompleted)

emitted of type is [Bool] , I don’t understand ’ .element’

Hi @viho,
the element comes from the XCUIElementQuery.h which is part of the Xcode testing framework rather than a Data Model or structure.

It is described as

/*! Returns an element that will use the query for resolution. */
@property (readonly) XCUIElement *element;

The three elements come from the query prior to the code snip you have posted which is

    DispatchQueue.main.async {
        accountSubject.onNext(.authorized(AccessToken()))
        accountSubject.onNext(.unavailable)
        accountSubject.onCompleted()
    }

The Bool array relates to the results of each of these queries.

Hope that helps

Cheers,

Jayant

1 Like

I think the correct code here would be

let emitted = try! loggedIn
    .take(3)
    .materialize() // missing
    .toBlocking(timeout: 1)
    .toArray()
3 Likes

Hi @kaichen,
Thank you for pointing that out, however the original question from @viho was about where does .element come from. And for anyone new to XCode Testing or not having used it enough would almost think that .element was part of the structure being tested.

cheers,

Jayant

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.