Repository navigation
Expand file tree
/
Copy pathtest_lib.dart
More file actions
72 lines (56 loc) · 1.71 KB
/
Copy pathtest_lib.dart
File metadata and controls
72 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
library test_lib.test_lib;
import 'package:guinness/guinness_html.dart' as gns;
export 'package:guinness/guinness_html.dart';
import 'package:unittest/unittest.dart' hide expect;
import 'dart:mirrors';
import 'dart:async';
import 'package:angular2/src/reflection/reflection.dart';
import 'package:angular2/src/facade/dom.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
bool IS_DARTIUM = true;
Expect expect(actual, [matcher]) {
final expect = new Expect(actual);
if (matcher != null) expect.to(matcher);
return expect;
}
class Expect extends gns.Expect {
Expect(actual) : super(actual);
NotExpect get not => new NotExpect(actual);
void toEqual(expected) => toHaveSameProps(expected);
void toThrowError([message=""]) => this.toThrowWith(message: message);
void toBePromise() => _expect(actual is Future, equals(true));
void toImplement(expected) => toBeA(expected);
Function get _expect => gns.guinness.matchers.expect;
}
class NotExpect extends gns.NotExpect {
NotExpect(actual) : super(actual);
void toEqual(expected) => toHaveSameProps(expected);
}
beforeEach(fn) {
gns.guinnessEnableHtmlMatchers();
gns.beforeEach(_enableReflection(fn));
}
it(name, fn) {
gns.it(name, _enableReflection(_handleAsync(fn)));
}
iit(name, fn) {
gns.iit(name, _enableReflection(_handleAsync(fn)));
}
_enableReflection(fn) {
return () {
reflector.reflectionCapabilities = new ReflectionCapabilities();
return fn();
};
}
_handleAsync(fn) {
ClosureMirror cm = reflect(fn);
MethodMirror mm = cm.function;
var completer = new Completer();
if (mm.parameters.length == 1) {
return () {
cm.apply([completer.complete]);
return completer.future;
};
}
return fn;
}