refactor(core): move Meta methods that only have one version from DomAdapter (#32408)
PR Close #32408
This commit is contained in:

committed by
Miško Hevery

parent
1a7c79746d
commit
89434e09c2
@ -35,11 +35,11 @@ class SomeComponent {
|
||||
const doc = TestBed.get(DOCUMENT);
|
||||
const rootEl =
|
||||
<HTMLElement>getContent(createTemplate(`<${selector}></${selector}>`)).firstChild;
|
||||
const oldRoots = getDOM().querySelectorAll(doc, selector);
|
||||
const oldRoots = doc.querySelectorAll(selector);
|
||||
for (let i = 0; i < oldRoots.length; i++) {
|
||||
getDOM().remove(oldRoots[i]);
|
||||
}
|
||||
getDOM().appendChild(doc.body, rootEl);
|
||||
doc.body.appendChild(rootEl);
|
||||
}
|
||||
|
||||
type CreateModuleOptions =
|
||||
|
@ -883,7 +883,7 @@ class TestCmptWithPropBindings {
|
||||
|
||||
// Move the content element outside the component
|
||||
// so that it can't be reached via querySelector.
|
||||
getDOM().appendChild(parent, content);
|
||||
parent.appendChild(content);
|
||||
|
||||
expect(fixture.debugElement.query(By.css('.content'))).toBeTruthy();
|
||||
|
||||
|
@ -21,13 +21,13 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
|
||||
const t = getDOM().getDefaultDocument().createTextNode('hello');
|
||||
expect(isTextNode(t)).toBe(true);
|
||||
const d = getDOM().createElement('div');
|
||||
getDOM().appendChild(d, t);
|
||||
d.appendChild(t);
|
||||
expect(d.innerHTML).toEqual('hello');
|
||||
});
|
||||
|
||||
it('should set className via the class attribute', () => {
|
||||
const d = getDOM().createElement('div');
|
||||
getDOM().setAttribute(d, 'class', 'class1');
|
||||
d.setAttribute('class', 'class1');
|
||||
expect(d.className).toEqual('class1');
|
||||
});
|
||||
|
||||
@ -45,9 +45,9 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
||||
it('should return the value of the base element', () => {
|
||||
const baseEl = getDOM().createElement('base');
|
||||
getDOM().setAttribute(baseEl, 'href', '/drop/bass/connon/');
|
||||
baseEl.setAttribute('href', '/drop/bass/connon/');
|
||||
const headEl = defaultDoc.head;
|
||||
getDOM().appendChild(headEl, baseEl);
|
||||
headEl.appendChild(baseEl);
|
||||
|
||||
const baseHref = getDOM().getBaseHref(defaultDoc);
|
||||
headEl.removeChild(baseEl);
|
||||
@ -58,9 +58,9 @@ import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
||||
it('should return a relative url', () => {
|
||||
const baseEl = getDOM().createElement('base');
|
||||
getDOM().setAttribute(baseEl, 'href', 'base');
|
||||
baseEl.setAttribute('href', 'base');
|
||||
const headEl = defaultDoc.head;
|
||||
getDOM().appendChild(headEl, baseEl);
|
||||
headEl.appendChild(baseEl);
|
||||
|
||||
const baseHref = getDOM().getBaseHref(defaultDoc) !;
|
||||
headEl.removeChild(baseEl);
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)');
|
||||
});
|
||||
|
@ -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();
|
||||
|
@ -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)');
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ const removeEventListener = '__zone_symbol__removeEventListener' as 'removeEvent
|
||||
elementDef(0, NodeFlags.None, null, null, 0, 'div', [['title', 'a']]),
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
expect(getDOM().getAttribute(rootNodes[0], 'title')).toBe('a');
|
||||
expect(rootNodes[0].getAttribute('title')).toBe('a');
|
||||
});
|
||||
|
||||
it('should add debug information to the renderer', () => {
|
||||
@ -114,8 +114,8 @@ const removeEventListener = '__zone_symbol__removeEventListener' as 'removeEvent
|
||||
Services.checkAndUpdateView(view);
|
||||
|
||||
const el = rootNodes[0];
|
||||
expect(getDOM().getAttribute(el, 'a1')).toBe('v1');
|
||||
expect(getDOM().getAttribute(el, 'a2')).toBe('v2');
|
||||
expect(el.getAttribute('a1')).toBe('v1');
|
||||
expect(el.getAttribute('a2')).toBe('v2');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -55,8 +55,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
|
||||
// 2 anchors + 2 elements
|
||||
const rootChildren = rootNodes[0].childNodes;
|
||||
expect(rootChildren.length).toBe(4);
|
||||
expect(getDOM().getAttribute(rootChildren[1], 'name')).toBe('child0');
|
||||
expect(getDOM().getAttribute(rootChildren[2], 'name')).toBe('child1');
|
||||
expect(rootChildren[1].getAttribute('name')).toBe('child0');
|
||||
expect(rootChildren[2].getAttribute('name')).toBe('child1');
|
||||
|
||||
rf.begin !();
|
||||
detachEmbeddedView(viewContainerData, 1);
|
||||
@ -90,8 +90,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
|
||||
// 2 anchors + 2 elements
|
||||
const rootChildren = rootNodes[0].childNodes;
|
||||
expect(rootChildren.length).toBe(4);
|
||||
expect(getDOM().getAttribute(rootChildren[1], 'name')).toBe('child1');
|
||||
expect(getDOM().getAttribute(rootChildren[2], 'name')).toBe('child0');
|
||||
expect(rootChildren[1].getAttribute('name')).toBe('child1');
|
||||
expect(rootChildren[2].getAttribute('name')).toBe('child0');
|
||||
});
|
||||
|
||||
it('should include embedded views in root nodes', () => {
|
||||
@ -107,8 +107,8 @@ import {compViewDef, compViewDefFactory, createAndGetRootNodes, createEmbeddedVi
|
||||
|
||||
const rootNodes = rootRenderNodes(parentView);
|
||||
expect(rootNodes.length).toBe(3);
|
||||
expect(getDOM().getAttribute(rootNodes[1], 'name')).toBe('child0');
|
||||
expect(getDOM().getAttribute(rootNodes[2], 'name')).toBe('after');
|
||||
expect(rootNodes[1].getAttribute('name')).toBe('child0');
|
||||
expect(rootNodes[2].getAttribute('name')).toBe('after');
|
||||
});
|
||||
|
||||
it('should dirty check embedded views', () => {
|
||||
|
@ -340,7 +340,7 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, createRootView, createAndGetR
|
||||
expect(instance.b).toBe('v2');
|
||||
|
||||
const el = rootNodes[0];
|
||||
expect(getDOM().getAttribute(el, 'ng-reflect-a')).toBe('v1');
|
||||
expect(el.getAttribute('ng-reflect-a')).toBe('v1');
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user