refactor(core): move server-only DomAdapter methods into ServerRenderer (#32408)

PR Close #32408
This commit is contained in:
Kara Erickson
2019-08-29 21:24:33 -07:00
committed by Miško Hevery
parent 1ed3531049
commit 970b58b13f
16 changed files with 61 additions and 123 deletions

View File

@ -1589,7 +1589,7 @@ const DEFAULT_COMPONENT_ID = '1';
engine.flush();
resetLog();
const element = getDOM().querySelector(fixture.nativeElement, '.ng-if');
const element = fixture.nativeElement.querySelector('.ng-if');
assertHasParent(element, true);
cmp.exp = false;

View File

@ -18,7 +18,7 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
});
it('should be able to create text nodes and use them with the other APIs', () => {
const t = getDOM().createTextNode('hello');
const t = getDOM().getDefaultDocument().createTextNode('hello');
expect(isTextNode(t)).toBe(true);
const d = getDOM().createElement('div');
getDOM().appendChild(d, t);
@ -71,7 +71,7 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
getDOM().appendChild(headEl, baseEl);
const baseHref = getDOM().getBaseHref(defaultDoc);
getDOM().removeChild(headEl, baseEl);
headEl.removeChild(baseEl);
getDOM().resetBaseElement();
expect(baseHref).toEqual('/drop/bass/connon/');
@ -84,7 +84,7 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
getDOM().appendChild(headEl, baseEl);
const baseHref = getDOM().getBaseHref(defaultDoc) !;
getDOM().removeChild(headEl, baseEl);
headEl.removeChild(baseEl);
getDOM().resetBaseElement();
expect(baseHref.endsWith('/base')).toBe(true);

View File

@ -1694,7 +1694,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'TITLE';
fixture.detectChanges();
const el = getDOM().querySelector(fixture.nativeElement, 'span');
const el = fixture.nativeElement.querySelector('span');
expect(el.title).toBeFalsy();
});
@ -1707,7 +1707,7 @@ function declareTests(config?: {useJit: boolean}) {
fixture.componentInstance.ctxProp = 'TITLE';
fixture.detectChanges();
const el = getDOM().querySelector(fixture.nativeElement, 'span');
const el = fixture.nativeElement.querySelector('span');
expect(getDOM().getProperty(el, 'title')).toEqual('TITLE');
});
});
@ -2685,16 +2685,12 @@ class ComponentWithoutView {
@Directive({selector: '[no-duplicate]'})
class DuplicateDir {
constructor(elRef: ElementRef) {
getDOM().setText(elRef.nativeElement, elRef.nativeElement.textContent + 'noduplicate');
}
constructor(elRef: ElementRef) { elRef.nativeElement.textContent += 'noduplicate'; }
}
@Directive({selector: '[no-duplicate]'})
class OtherDuplicateDir {
constructor(elRef: ElementRef) {
getDOM().setText(elRef.nativeElement, elRef.nativeElement.textContent + 'othernoduplicate');
}
constructor(elRef: ElementRef) { elRef.nativeElement.textContent += 'othernoduplicate'; }
}
@Directive({selector: 'directive-throwing-error'})

View File

@ -136,8 +136,9 @@ describe('projection', () => {
componentFactoryResolver.resolveComponentFactory(MultipleContentTagsComponent);
expect(componentFactory.ngContentSelectors).toEqual(['h1', '*']);
const nodeOne = getDOM().createTextNode('one');
const nodeTwo = getDOM().createTextNode('two');
const nodeOne = getDOM().getDefaultDocument().createTextNode('one');
const nodeTwo = getDOM().getDefaultDocument().createTextNode('two');
const component = componentFactory.create(injector, [[nodeOne], [nodeTwo]]);
expect(component.location.nativeElement).toHaveText('(one, two)');
});
@ -175,9 +176,9 @@ describe('projection', () => {
componentFactoryResolver.resolveComponentFactory(MultipleContentTagsComponent);
expect(componentFactory.ngContentSelectors).toEqual(['h1', '*', 'h2']);
const nodeOne = getDOM().createTextNode('one');
const nodeTwo = getDOM().createTextNode('two');
const nodeThree = getDOM().createTextNode('three');
const nodeOne = getDOM().getDefaultDocument().createTextNode('one');
const nodeTwo = getDOM().getDefaultDocument().createTextNode('two');
const nodeThree = getDOM().getDefaultDocument().createTextNode('three');
const component = componentFactory.create(injector, [[nodeOne], [nodeTwo], [nodeThree]]);
component.changeDetectorRef.detectChanges();
expect(component.location.nativeElement.textContent.trim()).toBe('1one 2two 3three');