This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1
1
library angular;
2
2
3
3
import "dart:mirrors" ;
4
+ import "dart:async" as async;
4
5
import "dart:json" as json;
5
6
import 'dart:html' as dom;
6
7
import 'package:di/di.dart' ;
@@ -16,6 +17,7 @@ part 'directives/ng_mustache.dart';
16
17
part 'directives/ng_repeat.dart' ;
17
18
part 'dom_utilities.dart' ;
18
19
part 'exception_handler.dart' ;
20
+ part 'http.dart' ;
19
21
part 'interpolate.dart' ;
20
22
part 'mirrors.dart' ;
21
23
part 'node_cursor.dart' ;
Original file line number Diff line number Diff line change
1
+ part of angular;
2
+
3
+ class Http {
4
+ async .Future <String > getString (String url, {bool withCredentials, void onProgress (dom.ProgressEvent e)}) =>
5
+ dom.HttpRequest .getString (url, withCredentials, onProgress);
6
+ }
Original file line number Diff line number Diff line change
1
+ library ng_mock_http;
2
+
3
+
4
+ import 'dart:async' ;
5
+ import 'dart:html' ;
6
+ import 'package:angular/angular.dart' ;
7
+
8
+ class MockHttp extends Http {
9
+ Map <String , String > gets = {};
10
+ expectGET (url, content) {
11
+ gets[url] = content;
12
+ }
13
+
14
+ Future <String > getString (String url, {bool withCredentials, void onProgress (ProgressEvent e)}) {
15
+ if (! gets.containsKey (url)) throw "Unexpected URL $url " ;
16
+ return new Future .value (gets.remove (url));
17
+ }
18
+ }
19
+
20
+ main () {}
Original file line number Diff line number Diff line change
1
+ import "_specs.dart" ;
2
+ import "_http.dart" ;
3
+
4
+ main () {
5
+ describe ("MockHttp" , () {
6
+ MockHttp http;
7
+ beforeEach (() {
8
+ http = new MockHttp ();
9
+ });
10
+
11
+ it ('should replay an http request' , () {
12
+ http.expectGET ('request' , 'response' );
13
+ http.getString ('request' ).then (expectAsync1 ((data) {
14
+ expect (data).toEqual ('response' );
15
+ }));
16
+ });
17
+
18
+ it ('should barf on an unseen request' , () {
19
+ expect (() {
20
+ http.getString ('unknown' );
21
+ }).toThrow ('Unexpected URL unknown' );
22
+ });
23
+ });
24
+ }
You can’t perform that action at this time.
0 commit comments