Skip to content

containExactly* assertions don't respect given verifier #3970

@AlexLamaison-UnlikelyAI

Description

Which version of Kotest are you using

Using Kotest 5.8.0.

containExactly and containExactlyInAnyOrder takes a verifier parameter, but doesn't respect it in the matching logic. For example, the first two of these tests fail when they should pass:

class ContainIgnoringFieldsTest {

  data class Foo(val a: Int, val b: String)

  @Test
  fun testAnyOrder() {
    listOf(Foo(1, "a"), Foo(2, "b")) should
        containExactlyInAnyOrder(
            listOf(Foo(3, "a"), Foo(4, "b")), Equality.byReflectionIgnoringFields(Foo::a))
  }

  @Test
  fun test() {
    listOf(Foo(1, "a"), Foo(2, "b")) should
        containExactly(
            listOf(Foo(3, "a"), Foo(4, "b")), Equality.byReflectionIgnoringFields(Foo::a))
  }

  @Test
  fun testAll() {
    listOf(Foo(1, "a"), Foo(2, "b")) should
        containAll(listOf(Foo(3, "a"), Foo(4, "b")), Equality.byReflectionIgnoringFields(Foo::a))
  }
}

Metadata

Metadata

Assignees

Labels

bug 🐛Issues that report a problem or error in the code.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions