Skip to content

Commit 2612546

Browse files
marclavalgoderbauer
authored andcommitted
fix(test_lib): run unit tests in default Documnent
Closes angular#3501 Fixes angular#3475
1 parent de19a47 commit 2612546

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

modules/angular2/src/test_lib/test_component_builder.ts

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export class TestComponentBuilder {
138138
var doc = this._injector.get(DOCUMENT_TOKEN);
139139

140140
// TODO(juliemr): can/should this be optional?
141+
var oldRoots = DOM.querySelectorAll(doc, '[id^=root]');
142+
for (var i = 0; i < oldRoots.length; i++) {
143+
DOM.remove(oldRoots[i]);
144+
}
141145
DOM.appendChild(doc.body, rootEl);
142146

143147

modules/angular2/src/test_lib/test_injector.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function _getAppBindings() {
9393

9494
// The document is only available in browser environment
9595
try {
96-
appDoc = DOM.createHtmlDocument();
96+
appDoc = DOM.defaultDoc();
9797
} catch (e) {
9898
appDoc = null;
9999
}

modules/angular2/test/forms/integration_spec.ts

-6
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,6 @@ export function main() {
736736
rootTC.componentInstance.form = form;
737737
rootTC.detectChanges();
738738

739-
// In IE, the element needs to be appended to the real DOM,
740-
// otherwise setting .selectionStart fails with "unspecified error"
741-
var isIE = DOM.getUserAgent().indexOf("Trident") > -1;
742-
if (isIE) DOM.appendChild(DOM.defaultDoc().body, rootTC.nativeElement);
743-
744739
var input = rootTC.query(By.css("input")).nativeElement;
745740
input.value = "aa";
746741
input.selectionStart = 1;
@@ -751,7 +746,6 @@ export function main() {
751746

752747
// selection start has not changed because we did not reset the value
753748
expect(input.selectionStart).toEqual(1);
754-
if (isIE) DOM.removeChild(DOM.defaultDoc().body, rootTC.nativeElement);
755749
})));
756750
});
757751
});

0 commit comments

Comments
 (0)