Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 @TestOn('vm') | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 import 'package:http/http.dart' as http; | |
| 11 import 'package:shelf/shelf.dart'; | |
|
kevmoo
2015/10/22 00:44:26
unused import
nweiz
2015/10/26 21:32:44
Done.
| |
| 12 import 'package:shelf/shelf_io.dart'; | |
| 13 import 'package:test/test.dart'; | |
| 14 | |
| 15 import 'test_util.dart'; | |
| 16 | |
| 17 void main() { | |
| 18 var server; | |
|
kevmoo
2015/10/22 00:44:26
type things when there is no way for inference to
nweiz
2015/10/26 21:32:44
This is a test—if there are bugs the tests will fa
| |
| 19 setUp(() async { | |
| 20 server = await IOServer.bind(InternetAddress.LOOPBACK_IP_V4, 0); | |
| 21 }); | |
| 22 | |
| 23 tearDown(() => server.close()); | |
| 24 | |
| 25 test("serves HTTP requests with the mounted handler", () async { | |
| 26 server.mount(syncHandler); | |
| 27 expect(await http.read(server.url), equals('Hello from /')); | |
| 28 }); | |
| 29 | |
| 30 test("delays HTTP requests until a handler is mounted", () async { | |
| 31 expect(http.read(server.url), completion(equals('Hello from /'))); | |
| 32 await new Future.delayed(Duration.ZERO); | |
| 33 | |
| 34 server.mount(asyncHandler); | |
| 35 }); | |
| 36 | |
| 37 test("disallows more than one handler from being mounted", () async { | |
| 38 server.mount((_) {}); | |
| 39 expect(() => server.mount((_) {}), throwsStateError); | |
|
kevmoo
2015/10/22 00:44:26
actually check for your StateError message – since
nweiz
2015/10/26 21:32:44
Checking for specific messages in tests is general
| |
| 40 expect(() => server.mount((_) {}), throwsStateError); | |
| 41 }); | |
| 42 } | |
| OLD | NEW |