2014-10-02 19:27:01 +00:00
|
|
|
library test_lib.test_lib;
|
2014-09-30 18:56:33 +00:00
|
|
|
|
|
|
|
|
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';
|
2015-02-05 21:08:05 +00:00
|
|
|
import 'package:angular2/src/reflection/reflection.dart';
|
|
|
|
|
import 'package:angular2/src/facade/dom.dart';
|
|
|
|
|
import 'package:angular2/src/reflection/reflection_capabilities.dart';
|
2014-09-30 18:56:33 +00:00
|
|
|
|
2014-11-07 17:31:51 +00:00
|
|
|
bool IS_DARTIUM = true;
|
|
|
|
|
|
2014-09-30 18:56:33 +00:00
|
|
|
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);
|
|
|
|
|
|
2014-10-29 18:26:52 +00:00
|
|
|
NotExpect get not => new NotExpect(actual);
|
|
|
|
|
|
|
|
|
|
void toEqual(expected) => toHaveSameProps(expected);
|
2014-10-20 19:17:06 +00:00
|
|
|
void toThrowError([message=""]) => this.toThrowWith(message: message);
|
2014-10-10 19:44:56 +00:00
|
|
|
void toBePromise() => _expect(actual is Future, equals(true));
|
2014-11-25 23:16:53 +00:00
|
|
|
void toImplement(expected) => toBeA(expected);
|
2014-09-30 18:56:33 +00:00
|
|
|
Function get _expect => gns.guinness.matchers.expect;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 18:26:52 +00:00
|
|
|
class NotExpect extends gns.NotExpect {
|
|
|
|
|
NotExpect(actual) : super(actual);
|
|
|
|
|
|
|
|
|
|
void toEqual(expected) => toHaveSameProps(expected);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-21 23:13:01 +00:00
|
|
|
beforeEach(fn) {
|
2015-01-08 17:11:33 +00:00
|
|
|
gns.guinnessEnableHtmlMatchers();
|
2014-11-21 23:13:01 +00:00
|
|
|
gns.beforeEach(_enableReflection(fn));
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-30 18:56:33 +00:00
|
|
|
it(name, fn) {
|
2014-11-20 20:07:48 +00:00
|
|
|
gns.it(name, _enableReflection(_handleAsync(fn)));
|
2014-09-30 18:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iit(name, fn) {
|
2014-11-20 20:07:48 +00:00
|
|
|
gns.iit(name, _enableReflection(_handleAsync(fn)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_enableReflection(fn) {
|
|
|
|
|
return () {
|
|
|
|
|
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
|
|
|
|
return fn();
|
|
|
|
|
};
|
2014-09-30 18:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_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;
|
2014-12-06 02:30:45 +00:00
|
|
|
}
|