I want to make a custom HttpRequest to unit test my api code. The code I want to test:
if (WebSocketTransformer.isUpgradeRequest(request)) {
await webSocketRequest.handleRequest(
request: request, streamController: streamController);
}
The method WebSocketTransformer
checks the method and the headers content. Therefore I have to hand in a HttpRequest
.
HttpRequest mockWSRequest;
mockWSrequest.headers.set('connection', 'upgrade');
But how can I set the HttpRequest
's method?
If you're talking about dart:io
's HttpRequest
class, that class is abstract
and cannot be directly instantiated. If you want to create a mock, then you would have your mock implement the HttpRequest
interface and add an implementation for its method
getter to return 'GET'
or 'POST'
as desired.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.