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

keyValue

fun <K, V : Any> keyValue(key: K, valueAssertionCreatorOrNull: (Expect<V>.() -> Unit)?): KeyWithValueCreator<K, V> (source)

Helper function to create a KeyWithValueCreator based on the given key and valueAssertionCreatorOrNull -- allows expressing Pair<K, (Expect<V>.() -> Unit)?>.

expect(mapOf(1 to "a")) toContain keyValue(1) { // subject inside this block is of type String (actually "a")
    this toEqual "a"
}

fails {
    expect(mapOf(1 to "a")) toContain keyValue(1) {  // subject inside this block is of type String (actually "a")
        this toEqual "b"          // fails because "a" is not equal to "b"
    }
}