I want to test equality between these two request objects but I can not figure out how to implement the hash
and equality
operator on a third-party package for example http
package.
How can I use equatable
package on the Response object of http
package?
import 'package:http/http.dart' as http;
test('equality test', () async {
final uri = baseUri.replace(path: 'account/login');
final request = http.Request(RequestMethod.post, uri);
final request2 = http.Request(RequestMethod.post, uri);
expect(request, equals(request2));
});
The output is
Expected: Request:<POST https://test.webapi.odinpool.com:1989/account/login>
Actual: Request:<POST https://test.webapi.odinpool.com:1989/account/login>
Which it doesn’t complete successfully.
I want to test the remote server API to call the correct API endpoint when creating the request object and test the method with verify.called(1)
method but it seems the test package can not test equality between http.Request
objects.
2
Answers
Thanks to @Richard Heap comment I came up with a solution:
This
RequestX
class compared two objects successfully.I think your best bet is going to be to either find/create a function to do a deep check.
In reality though this is going to be a pretty rare need case. Either when you compare you are going to have a reference to the same object which will evaluate to true: