Kirill Zhukov
05/09/2023, 6:36 AMshouldBeInstanceOf
not to work with generics? This test passes when I don’t think it should?
test("test") {
listOf(1).shouldBeInstanceOf<List<String>>()
}
Ivan Pavlov
05/09/2023, 6:45 AMKirill Zhukov
05/09/2023, 6:47 AMWhen using shouldBeInstanceOf<T> or shouldBeTypeOf<T>, the assertions can now use generic contracts to smart case down to generic instances.
For example, consider the following example where we are given an Any. After invokingwith a generic type, the type is smart casted if the assertion passes.shouldBeTypeOf
```val list: Any = arrayListOf(1, 2, 3)
list.shouldBeTypeOf<ArrayList<Int>>()
list[0] shouldBe 1 // can only work with a smart case```
Adam S
05/09/2023, 6:47 AMList<Int>
, but it should be possible to verify all the elements are StringslistOf(1, 2, 3).shouldForAll { it.shouldBeInstanceOf<String>() }
shouldBeTypeOf<ArrayList<Int>>()
, not shouldBeInstanceOf<ArrayList<Int>>()
- could you try both?Ivan Pavlov
05/09/2023, 6:52 AMKirill Zhukov
05/09/2023, 6:56 AMshouldBeTypeOf
doesn’t work eitherErr<T>: Result
generic data class that I want to assert: someResult.shouldBeOfType<Err<SomeError>>()
someResult.shouldBeErrOfType<SomeError>()
Javier
05/09/2023, 10:29 AM