Skip to content

Unexpected output using with on a map #252

@dump247

Description

@dump247

Given this example

class Foo {
    val bar: Map<String, Any?> = mapOf("biz" to mapOf("a" to 1))
}

@Test
fun x() {
    expectThat(Foo()) {
        with({ bar }) {
            getValue("biz").isA<Map<String, Int>>().and {
                hasEntry("a", 2)
            }
        }
    }
}

The test produces the following output

▼ Expect that Foo@133aca79:
  ▼ hasEntry("a", 2):
    ✓ has an entry with the key "biz"
    ▼ entry ["biz"]:
      ✓ is an instance of java.util.Map
      ✓ has an entry with the key "a"
      ▼ entry ["a"]:
        ✗ is equal to 2
                found 1

The expected output is

▼ Expect that Foo@133aca79:
  ▼ bar:
    ✓ has an entry with the key "biz"
    ▼ entry ["biz"]:
      ✓ is an instance of java.util.Map
      ✓ has an entry with the key "a"
      ▼ entry ["a"]:
        ✗ is equal to 2
                found 1

strikt 0.32.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions