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>>()
}
Kirill Zhukov
05/09/2023, 6:36 AMIvan Pavlov
05/09/2023, 6:45 AMKirill Zhukov
05/09/2023, 6:47 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 StringsAdam S
05/09/2023, 6:48 AMlistOf(1, 2, 3).shouldForAll { it.shouldBeInstanceOf<String>() }
Adam S
05/09/2023, 6:50 AMshouldBeTypeOf<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 eitherKirill Zhukov
05/09/2023, 6:57 AMKirill Zhukov
05/09/2023, 6:57 AMErr<T>: Result
generic data class that I want to assert: someResult.shouldBeOfType<Err<SomeError>>()
Kirill Zhukov
05/09/2023, 6:58 AMsomeResult.shouldBeErrOfType<SomeError>()
Javier
05/09/2023, 10:29 AMJavier
05/09/2023, 10:29 AM