doc / ch.tutteli.atrium.api.infix.en_GB / first

first

val <K, T : Pair<K, *>> Expect<T>.first: Expect<K> (source)

Creates an Expect for the property Pair.first of the subject of this expectation, so that further fluent calls are assertions about it.

val pair = 1 to "one"

expect(pair)
    .first toBeLessThan 2 toBeGreaterThan 0
//   | subject is now of type Int (actually 1)

fails {
    expect(pair)
        .first toBeGreaterThan 2 toBeLessThan 0
    //   |         |             | not reported because `toBeGreaterThan` already fails
    //   |         | fails
    //   | subject is now of type Int (actually 1)
    //    use ` first { ... }` if you want that all assertions are evaluated
}

Return
The newly created Expect for the extracted feature.

infix fun <K, V, T : Pair<K, V>> Expect<T>.first(assertionCreator: Expect<K>.() -> Unit): Expect<T> (source)

Expects that the property Pair.first of the subject of this expectation holds all assertions the given assertionCreator creates for it and returns an Expect for the current subject of this expectation.

val pair = 1 to "one"

expect(pair)
    .first { // subject inside this block is of type Int (actually 1)
        it toBeLessThan 2
    } // subject here is back to type Pair<Int, String>
    .first { // subject inside this block is of type Int (actually 1)
        it toBeGreaterThan 0
    }

fails {
    // all assertions are evaluated inside an assertion group block; for more details:
    // https://github.com/robstoll/atrium#define-single-assertions-or-assertion-groups
    expect(pair)
        .first { // subject inside this block is of type Int (actually 1)
            it toBeGreaterThan 2 //fails
            it toBeLessThan 0    // still evaluated even though `toBeGreaterThan` already fails
            //                      use ` first o` if you want a fail fast behaviour
        }
}

Return
an Expect for the subject of this expectation.