TextRef icon indicating copy to clipboard operation
TextRef copied to clipboard

Issue with TextRef Comparison

Open vlh-ioki opened this issue 1 year ago • 1 comments

In our unit tests, I've encountered an issue when comparing TextRef objects using the isEqualTo function from the assertion library. The test fails when comparing two TextRef objects directly. Here is an example of the failing test:

expectThat(viewModel.viewState.value)
    .isA<ViewState.Ready>()
    .get { selectedItem?.subtitle }
    .isEqualTo(expected)

To make the test pass, we have to convert the TextRef objects to String before comparing them:

expectThat(viewModel.viewState.value)
    .isA<ViewState.Ready>()
    .get { selectedItem?.subtitle.toString() }
    .isEqualTo(expected.toString())

This workaround is not ideal as it requires additional conversion and may not accurately reflect the intended behavior of the code under test. I believe this issue might be related to how TextRef implements equality checks. I would appreciate it if you could look into this issue and provide guidance on how to properly compare TextRef objects in our tests.

vlh-ioki avatar Apr 26 '24 11:04 vlh-ioki

Could you please provide an reproducer?

In fact, all of the tests using the equal function.

There is even an test that tests the equal function 🫠

StefMa avatar May 01 '24 19:05 StefMa

Closed due of inactivity of reporter. Feel free to comment back, we can open this issue again at any time 🙃

StefMa avatar Jul 18 '24 13:07 StefMa