diff --git a/lib/mock/module.dart b/lib/mock/module.dart
index 89fa2a709..2b5e9f13b 100644
--- a/lib/mock/module.dart
+++ b/lib/mock/module.dart
@@ -59,14 +59,16 @@ part 'mock_cache_register.dart';
*/
class AngularMockModule extends Module {
AngularMockModule() {
+ bind(MockApplication);
+ bind(Application, toImplementation: MockApplication);
bind(ExceptionHandler, toImplementation: RethrowExceptionHandler);
bind(TestBed);
bind(Probe);
bind(Logger);
bind(MockHttpBackend);
bind(CacheRegister, toImplementation: MockCacheRegister);
- bind(Element, toValue: document.body);
- bind(Node, toValue: document.body);
+ bind(Element, toFactory: (app) => app.element, inject: [MockApplication]);
+ bind(Node, inject: [Element]);
bind(HttpBackend, toInstanceOf: MOCK_HTTP_BACKEND_KEY);
bind(VmTurnZone, toFactory: () {
return new VmTurnZone()
@@ -78,3 +80,20 @@ class AngularMockModule extends Module {
bind(DefaultPlatformShim, toInstanceOf: MockWebPlatformShim);
}
}
+
+class MockApplication extends Application {
+ var _element;
+
+ Element get element {
+ if (_element == null) {
+ _element = new DivElement()..attributes['ng-app'] = '';
+ }
+ return _element;
+ }
+
+ void destroyElement() {
+ _element = null;
+ }
+
+ Injector createInjector() => throw 'MockApplications can not create injectors';
+}
diff --git a/lib/mock/test_injection.dart b/lib/mock/test_injection.dart
index 9450dbf92..4762458d6 100644
--- a/lib/mock/test_injection.dart
+++ b/lib/mock/test_injection.dart
@@ -1,9 +1,13 @@
library angular.mock.test_injection;
+import 'dart:html';
+
+import 'package:angular/application.dart';
import 'package:angular/application_factory.dart';
import 'package:angular/mock/module.dart';
import 'package:di/di.dart';
import 'dart:mirrors';
+import 'module.dart';
_SpecInjector _currentSpecInjector = null;
@@ -61,7 +65,7 @@ class _SpecInjector {
}
}
- reset() {
+ void reset() {
injector = null;
injectorCreateLocation = null;
}
@@ -161,3 +165,12 @@ void setUpInjector() {
void tearDownInjector() {
_currentSpecInjector = null;
}
+
+void cleanUpAppRoot() {
+ if (_currentSpecInjector.injector != null) {
+ var app = _currentSpecInjector.injector.get(Application);
+ assert(app is MockApplication);
+ app.destroyElement();
+ }
+ document.body.setInnerHtml('');
+}
diff --git a/test/_specs.dart b/test/_specs.dart
index b1a4923f6..7f4adc3d1 100644
--- a/test/_specs.dart
+++ b/test/_specs.dart
@@ -215,6 +215,7 @@ _removeNgBinding(node) {
main() {
gns.beforeEach(setUpInjector, priority:3);
+ gns.afterEach(cleanUpAppRoot);
gns.afterEach(tearDownInjector);
gns.guinnessEnableHtmlMatchers();
diff --git a/test/animate/ng_animate_spec.dart b/test/animate/ng_animate_spec.dart
index 86406a8c1..6ac5849b4 100644
--- a/test/animate/ng_animate_spec.dart
+++ b/test/animate/ng_animate_spec.dart
@@ -26,10 +26,6 @@ main() {
});
});
- afterEach(() {
- tearDownInjector();
- });
-
it('should control animations on elements', () {
_.compile('
');
_.rootScope.apply();
diff --git a/test/core_dom/event_handler_spec.dart b/test/core_dom/event_handler_spec.dart
index 3511527f6..25063bd89 100644
--- a/test/core_dom/event_handler_spec.dart
+++ b/test/core_dom/event_handler_spec.dart
@@ -20,49 +20,37 @@ main() {
describe('EventHandler', () {
Element ngAppElement;
beforeEachModule((Module module) {
- ngAppElement = new DivElement()..attributes['ng-app'] = '';
module..bind(BarComponent);
- module..bind(Node, toValue: ngAppElement);
- document.body.append(ngAppElement);
});
- afterEach(() {
- ngAppElement.remove();
- ngAppElement = null;
- });
-
- compile(_, html) {
- ngAppElement.setInnerHtml(html, treeSanitizer: new NullTreeSanitizer());
- _.compile(ngAppElement);
- return ngAppElement.firstChild;
- }
- it('should register and handle event', (TestBed _) {
- var e = compile(_,
+ it('should register and handle event', (TestBed _, Application app) {
+ var e = _.compile(
'''''');
_.triggerEvent(e, 'abc');
expect(_.rootScope.context['invoked']).toEqual(true);
});
- it('shoud register and handle event with long name', (TestBed _) {
- var e = compile(_,
+ it('shoud register and handle event with long name', (TestBed _, Application app) {
+ var e = _.compile(
'''''');
_.triggerEvent(e, 'my-new-event');
expect(_.rootScope.context['invoked']).toEqual(true);
});
- it('shoud have model updates applied correctly', (TestBed _) {
- var e = compile(_,
+ it('should have model updates applied correctly', (TestBed _, Application app) {
+ var e = _.compile(
'''{{description}}
''');
e.dispatchEvent(new Event('abc'));
_.rootScope.apply();
expect(e.text).toEqual("new description");
});
- it('shoud register event when shadow dom is used', async((TestBed _) {
- var e = compile(_,'');
+ it('should register event when shadow dom is used', async((TestBed _, Application app) {
+ var e = _.compile('');
+ document.body.append(app.element..append(e));
microLeap();
@@ -73,8 +61,8 @@ main() {
expect(ctrl.invoked).toEqual(true);
}));
- it('shoud handle event within content only once', async((TestBed _) {
- var e = compile(_,
+ it('shoud handle event within content only once', async((TestBed _, Application app) {
+ var e = _.compile(
'''
diff --git a/test/directive/ng_model_select_spec.dart b/test/directive/ng_model_select_spec.dart
index 0c263e71e..ba6266bad 100644
--- a/test/directive/ng_model_select_spec.dart
+++ b/test/directive/ng_model_select_spec.dart
@@ -7,16 +7,17 @@ import 'package:browser_detect/browser_detect.dart';
main() {
describe('input-select', () {
-
describe('ng-value', () {
TestBed _;
beforeEach((TestBed tb) => _ = tb);
- it('should retrieve using ng-value', () {
- _.compile(
+ it('should retrieve using ng-value', (Application app) {
+ var selectElement = _.compile(
'');
+ document.body.append(app.element..append(selectElement));
+
var r2d2 = {"name":"r2d2"};
var c3p0 = {"name":"c3p0"};
_.rootScope.context['robots'] = [ r2d2, c3p0 ];
@@ -27,14 +28,15 @@ main() {
_.rootScope.context['robot'] = r2d2;
_.rootScope.apply();
expect(_.rootScope.context['robot']).toEqual(r2d2);
- expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
+ expect(selectElement).toEqualSelect([['r2d2'], 'c3p0']);
});
- it('should retrieve using ng-value', () {
- _.compile(
+ it('should retrieve using ng-value', (Application app) {
+ var selectElement = _.compile(
'');
+ document.body.append(app.element..append(selectElement));
var r2d2 = { "name":"r2d2"};
var c3p0 = {"name":"c3p0"};
_.rootScope.context['robots'] = [ r2d2, c3p0 ];
@@ -45,7 +47,7 @@ main() {
_.rootScope.context['robot'] = [r2d2];
_.rootScope.apply();
expect(_.rootScope.context['robot']).toEqual([r2d2]);
- expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
+ expect(selectElement).toEqualSelect([['r2d2'], 'c3p0']);
});
});
@@ -56,7 +58,7 @@ main() {
describe('select-one', () {
it('should compile children of a select without a ngModel, but not create a model for it',
() {
- _.compile(
+ var selectElement = _.compile(
'