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)?>.

Samples

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

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