refactor(core): remove innerHTML and outerHTML testing utilities from DomAdapters (#32278)

PR Close #32278
This commit is contained in:
Kara Erickson
2019-08-22 14:14:36 -07:00
committed by atscott
parent 25f31f2a14
commit c3f9893d81
12 changed files with 32 additions and 49 deletions

View File

@ -13,7 +13,6 @@ import {Component, ViewChild} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
import {ivyEnabled} from '@angular/private/testing';
(function() {
// these tests are only mean't to be run within the DOM (for now)

View File

@ -54,7 +54,7 @@ import {el, stringifyElement} from '@angular/platform-browser/testing/src/browse
expect(getDOM().isTextNode(t)).toBe(true);
const d = getDOM().createElement('div');
getDOM().appendChild(d, t);
expect(getDOM().getInnerHTML(d)).toEqual('hello');
expect(d.innerHTML).toEqual('hello');
});
it('should set className via the class attribute', () => {

View File

@ -199,12 +199,12 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'Some <span>HTML</span>';
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.debugElement.children[0].nativeElement))
expect(fixture.debugElement.children[0].nativeElement.innerHTML)
.toEqual('Some <span>HTML</span>');
fixture.componentInstance.ctxProp = 'Some other <div>HTML</div>';
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.debugElement.children[0].nativeElement))
expect(fixture.debugElement.children[0].nativeElement.innerHTML)
.toEqual('Some other <div>HTML</div>');
});
@ -1726,7 +1726,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'hello';
fixture.detectChanges();
const html = getDOM().getInnerHTML(fixture.nativeElement);
const html = fixture.nativeElement.innerHTML;
expect(html).toContain('ng-reflect-dir-prop="hello"');
});
@ -1737,7 +1737,7 @@ function declareTests(config?: {useJit: boolean}) {
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();
const html = getDOM().getInnerHTML(fixture.nativeElement);
const html = fixture.nativeElement.innerHTML;
expect(html).toContain('ng-reflect-dir-prop="hello"');
expect(html).not.toContain('ng-reflect-title');
});
@ -1747,7 +1747,7 @@ function declareTests(config?: {useJit: boolean}) {
const fixture = TestBed.createComponent(ParentCmp);
fixture.detectChanges();
const html = getDOM().getInnerHTML(fixture.nativeElement);
const html = fixture.nativeElement.innerHTML;
expect(html).toContain('ng-reflect-test_="hello"');
});
@ -1761,7 +1761,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxBoolProp = true;
fixture.detectChanges();
const html = getDOM().getInnerHTML(fixture.nativeElement);
const html = fixture.nativeElement.innerHTML;
expect(html).toContain('"ng-reflect-ng-if": "true"');
});
@ -1776,7 +1776,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxBoolProp = true;
fixture.detectChanges();
const html = getDOM().getInnerHTML(fixture.nativeElement);
const html = fixture.nativeElement.innerHTML;
expect(html).toContain('"ng-reflect-ng-if": "true"');
});
@ -1790,7 +1790,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'hello';
fixture.detectChanges();
const html = getDOM().getInnerHTML(fixture.nativeElement);
const html = fixture.nativeElement.innerHTML;
expect(html).toContain('ng-reflect-dir-prop="hello"');
expect(html).toContain('ng-reflect-dir-prop2="hello"');
});
@ -1802,7 +1802,7 @@ function declareTests(config?: {useJit: boolean}) {
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.nativeElement)).toContain('[ERROR]');
expect(fixture.nativeElement.innerHTML).toContain('[ERROR]');
});
it('should not reflect undefined values', () => {
@ -1814,13 +1814,12 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'hello';
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.nativeElement))
.toContain('ng-reflect-dir-prop="hello"');
expect(fixture.nativeElement.innerHTML).toContain('ng-reflect-dir-prop="hello"');
fixture.componentInstance.ctxProp = undefined !;
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.nativeElement)).not.toContain('ng-reflect-');
expect(fixture.nativeElement.innerHTML).not.toContain('ng-reflect-');
});
it('should not reflect null values', () => {
@ -1832,13 +1831,12 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'hello';
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.nativeElement))
.toContain('ng-reflect-dir-prop="hello"');
expect(fixture.nativeElement.innerHTML).toContain('ng-reflect-dir-prop="hello"');
fixture.componentInstance.ctxProp = null !;
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.nativeElement)).not.toContain('ng-reflect-');
expect(fixture.nativeElement.innerHTML).not.toContain('ng-reflect-');
});
it('should reflect empty strings', () => {
@ -1850,7 +1848,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = '';
fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.nativeElement)).toContain('ng-reflect-dir-prop=""');
expect(fixture.nativeElement.innerHTML).toContain('ng-reflect-dir-prop=""');
});
it('should not reflect in comment nodes when the value changes to undefined', () => {
@ -1863,14 +1861,14 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxBoolProp = true;
fixture.detectChanges();
let html = getDOM().getInnerHTML(fixture.nativeElement);
let html = fixture.nativeElement.innerHTML;
expect(html).toContain('bindings={');
expect(html).toContain('"ng-reflect-ng-if": "true"');
fixture.componentInstance.ctxBoolProp = undefined !;
fixture.detectChanges();
html = getDOM().getInnerHTML(fixture.nativeElement);
html = fixture.nativeElement.innerHTML;
expect(html).toContain('bindings={');
expect(html).not.toContain('ng-reflect');
});
@ -1885,14 +1883,14 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxBoolProp = true;
fixture.detectChanges();
let html = getDOM().getInnerHTML(fixture.nativeElement);
let html = fixture.nativeElement.innerHTML;
expect(html).toContain('bindings={');
expect(html).toContain('"ng-reflect-ng-if": "true"');
fixture.componentInstance.ctxBoolProp = null !;
fixture.detectChanges();
html = getDOM().getInnerHTML(fixture.nativeElement);
html = fixture.nativeElement.innerHTML;
expect(html).toContain('bindings={');
expect(html).toContain('"ng-reflect-ng-if": null');
});
@ -1928,8 +1926,7 @@ function declareTests(config?: {useJit: boolean}) {
dir.myAttr = 'aaa';
fixture.detectChanges();
expect(getDOM().getOuterHTML(fixture.debugElement.children[0].nativeElement))
.toContain('my-attr="aaa"');
expect(fixture.debugElement.children[0].nativeElement.outerHTML).toContain('my-attr="aaa"');
});
if (getDOM().supportsDOMEvents()) {

View File

@ -574,7 +574,7 @@ describe('projection', () => {
const main = TestBed.createComponent(MainComp);
main.detectChanges();
expect(getDOM().getInnerHTML(main.nativeElement))
expect(main.nativeElement.innerHTML)
.toEqual(
'<cmp-a><cmp-b><cmp-d><i>cmp-d</i></cmp-d></cmp-b>' +
'<cmp-c><b>cmp-c</b></cmp-c></cmp-a>');
@ -586,7 +586,7 @@ describe('projection', () => {
const main = TestBed.createComponent(MainComp);
main.detectChanges();
expect(getDOM().getInnerHTML(main.nativeElement))
expect(main.nativeElement.innerHTML)
.toEqual(
'<cmp-a1>a1<cmp-b11>b11</cmp-b11><cmp-b12>b12</cmp-b12></cmp-a1>' +
'<cmp-a2>a2<cmp-b21>b21</cmp-b21><cmp-b22>b22</cmp-b22></cmp-a2>');

View File

@ -283,19 +283,19 @@ function declareTests(config?: {useJit: boolean}) {
// Make sure binding harmless values works.
ci.ctxProp = 'some <p>text</p>';
fixture.detectChanges();
expect(getDOM().getInnerHTML(e)).toEqual('some <p>text</p>');
expect(e.innerHTML).toEqual('some <p>text</p>');
ci.ctxProp = 'ha <script>evil()</script>';
fixture.detectChanges();
expect(getDOM().getInnerHTML(e)).toEqual('ha ');
expect(e.innerHTML).toEqual('ha ');
ci.ctxProp = 'also <img src="x" onerror="evil()"> evil';
fixture.detectChanges();
expect(getDOM().getInnerHTML(e)).toEqual('also <img src="x"> evil');
expect(e.innerHTML).toEqual('also <img src="x"> evil');
ci.ctxProp = 'also <iframe srcdoc="evil"></iframe> evil';
fixture.detectChanges();
expect(getDOM().getInnerHTML(e)).toEqual('also evil');
expect(e.innerHTML).toEqual('also evil');
});
});
});

View File

@ -9,7 +9,6 @@
import {ElementRef} from '@angular/core';
import {ChangeDetectorRef} from '@angular/core/src/change_detection/change_detection';
import {SpyObject} from '@angular/core/testing/src/testing_internal';
import {DomAdapter} from '@angular/platform-browser/src/dom/dom_adapter';
export class SpyChangeDetectorRef extends SpyObject {
constructor() {
@ -24,7 +23,3 @@ export class SpyIterableDifferFactory extends SpyObject {}
export class SpyElementRef extends SpyObject {
constructor() { super(ElementRef); }
}
export class SpyDomAdapter extends SpyObject {
constructor() { super(DomAdapter); }
}