I'm doing testing on render objects in Flutter. I'd like to check for inequality like this (simplified):
testWidgets('render object heights not equal', (WidgetTester tester) async { final renderObjectOneHeight = 10; final renderObjectTwoHeight = 11; expect(renderObjectOneHeight, notEqual(renderObjectTwoHeight)); });
I made up notEqual
because it doesn't exist. This doesn't work either:
!equals
I found a solution that works so I am posting my answer below Q&A style. I welcome any better solutions, though.
You can use isNot()
to negate the equals()
matcher.
final x = 1; final y = 2; expect(x, isNot(equals(y)));
Or as mentioned in the comments:
expect(x != y, true)
That actually seems a bit more readable to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With