I'm trying to create some simple unittests, here's the code:
import 'dart:io';
import 'package:unittest/unittest.dart';
void main() {
test('check if sent data equals expected data', () {
HttpServer.bind('127.0.0.1', 8080)
.then(expectAsync1((HttpServer server) {
server.listen((HttpRequest request) {
expect(request.runtimeType.toString(), equals('_HttpRequest'));
request.fold(new BytesBuilder(), (prev, next) {
prev.addAll(next);
return prev;
})
.then(expectAsync1((BytesBuilder bb) {
var bytes = bb.takeBytes(),
helloString = new String.fromCharCodes(bytes);
expect(helloString, equals('hello'));
request.response.write(helloString);
request.response.close();
server.close();
}));
});
}));
HttpClient client = new HttpClient();
client.get('127.0.0.1', 8080, '/')
.then((HttpClientRequest request) {
request.add('hello'.codeUnits);
return request.close();
});
});
}
Gives me an error: Breaking on exception: 'dart:async/stream_impl.dart': Failed assertion: line 149 pos 12: '! _isClosed' is not true.
After some workaround, I found out that the responsible one is request.add('hello'.codeUnits)
So now I have no way to add data to HttpClientRequest
. Any workaround?