refactor(core): move Meta methods that only have one version from DomAdapter (#32408)

PR Close #32408
This commit is contained in:
Kara Erickson
2019-08-30 12:52:48 -07:00
committed by Miško Hevery
parent 1a7c79746d
commit 89434e09c2
28 changed files with 88 additions and 111 deletions

View File

@ -114,12 +114,12 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'Initial aria label';
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'aria-label'))
expect(fixture.debugElement.children[0].nativeElement.getAttribute('aria-label'))
.toEqual('Initial aria label');
fixture.componentInstance.ctxProp = 'Changed aria label';
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'aria-label'))
expect(fixture.debugElement.children[0].nativeElement.getAttribute('aria-label'))
.toEqual('Changed aria label');
});
@ -131,8 +131,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'bar';
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'foo'))
.toEqual('bar');
expect(fixture.debugElement.children[0].nativeElement.getAttribute('foo')).toEqual('bar');
fixture.componentInstance.ctxProp = null !;
fixture.detectChanges();
@ -887,7 +886,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.nativeElement, 'role')).toEqual('button');
expect(fixture.debugElement.nativeElement.getAttribute('role')).toEqual('button');
});
it('should support updating host element via hostAttributes on host elements', () => {
@ -898,7 +897,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.detectChanges();
expect(getDOM().getAttribute(fixture.debugElement.children[0].nativeElement, 'role'))
expect(fixture.debugElement.children[0].nativeElement.getAttribute('role'))
.toEqual('button');
});
@ -1404,7 +1403,7 @@ function declareTests(config?: {useJit: boolean}) {
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
expect(getDOM().querySelectorAll(fixture.nativeElement, 'script').length).toEqual(0);
expect(fixture.nativeElement.querySelectorAll('script').length).toEqual(0);
});
it('should throw when using directives without selector in NgModule declarations', () => {
@ -2139,7 +2138,7 @@ class SimpleImperativeViewComponent {
constructor(self: ElementRef) {
const hostElement = self.nativeElement;
getDOM().appendChild(hostElement, el('hello imp view'));
hostElement.appendChild(el('hello imp view'));
}
}
@ -2663,7 +2662,7 @@ class SomeImperativeViewport {
this.view = this.vc.createEmbeddedView(this.templateRef);
const nodes = this.view.rootNodes;
for (let i = 0; i < nodes.length; i++) {
getDOM().appendChild(this.anchor, nodes[i]);
this.anchor.appendChild(nodes[i]);
}
}
}

View File

@ -524,8 +524,8 @@ describe('projection', () => {
const mainEl = main.nativeElement;
const div1 = mainEl.firstChild;
const div2 = getDOM().createElement('div');
getDOM().setAttribute(div2, 'class', 'redStyle');
getDOM().appendChild(mainEl, div2);
div2.setAttribute('class', 'redStyle');
mainEl.appendChild(div2);
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getComputedStyle(div2).color).toEqual('rgb(255, 0, 0)');
});
@ -544,7 +544,7 @@ describe('projection', () => {
const mainEl = main.nativeElement;
const div1 = mainEl.firstChild;
const div2 = getDOM().createElement('div');
getDOM().appendChild(mainEl, div2);
mainEl.appendChild(div2);
expect(getComputedStyle(div1).color).toEqual('rgb(255, 0, 0)');
expect(getComputedStyle(div2).color).toEqual('rgb(0, 0, 0)');
});

View File

@ -438,7 +438,7 @@ function declareTestsUsingBootstrap() {
beforeEach(inject([DOCUMENT], (doc: any) => {
destroyPlatform();
const el = getDOM().createElement(COMP_SELECTOR, doc);
getDOM().appendChild(doc.body, el);
doc.body.appendChild(el);
logger = new MockConsole();
errorHandler = new ErrorHandler();

View File

@ -177,13 +177,12 @@ function declareTests(config?: {useJit: boolean}) {
fixture.detectChanges();
// In the browser, reading href returns an absolute URL. On the server side,
// it just echoes back the property.
let value =
isAttribute ? getDOM().getAttribute(e, 'href') : getDOM().getProperty(e, 'href');
let value = isAttribute ? e.getAttribute('href') : getDOM().getProperty(e, 'href');
expect(value).toMatch(/.*\/?hello$/);
ci.ctxProp = 'javascript:alert(1)';
fixture.detectChanges();
value = isAttribute ? getDOM().getAttribute(e, 'href') : getDOM().getProperty(e, 'href');
value = isAttribute ? e.getAttribute('href') : getDOM().getProperty(e, 'href');
expect(value).toEqual('unsafe:javascript:alert(1)');
}