refactor(core): remove testing-only style utils from DomAdapters (#32291)
PR Close #32291
This commit is contained in:

committed by
Miško Hevery

parent
46caf88b2c
commit
ede5786d1e
@ -199,3 +199,16 @@ export function setCookie(name: string, value: string) {
|
||||
export function supportsWebAnimation(): boolean {
|
||||
return typeof(<any>Element).prototype['animate'] === 'function';
|
||||
}
|
||||
|
||||
export function hasStyle(element: any, styleName: string, styleValue?: string | null): boolean {
|
||||
const value = element.style[styleName] || '';
|
||||
return styleValue ? value == styleValue : value.length > 0;
|
||||
}
|
||||
|
||||
export function hasClass(element: any, className: string): boolean {
|
||||
return element.classList.contains(className);
|
||||
}
|
||||
|
||||
export function sortedClassList(element: any): any[] {
|
||||
return Array.prototype.slice.call(element.classList, 0).sort();
|
||||
}
|
||||
|
@ -10,7 +10,8 @@
|
||||
import {Type, ɵglobal as global} from '@angular/core';
|
||||
import {ComponentFixture} from '@angular/core/testing';
|
||||
import {By, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
import {isCommentNode} from './browser_util';
|
||||
|
||||
import {hasClass, hasStyle, isCommentNode} from './browser_util';
|
||||
|
||||
|
||||
|
||||
@ -186,7 +187,7 @@ _global.beforeEach(function() {
|
||||
function buildError(isNot: boolean) {
|
||||
return function(actual: any, className: string) {
|
||||
return {
|
||||
pass: getDOM().hasClass(actual, className) == !isNot,
|
||||
pass: hasClass(actual, className) == !isNot,
|
||||
get message() {
|
||||
return `Expected ${actual.outerHTML} ${isNot ? 'not ' : ''}to contain the CSS class "${className}"`;
|
||||
}
|
||||
@ -200,12 +201,11 @@ _global.beforeEach(function() {
|
||||
compare: function(actual: any, styles: {[k: string]: string}|string) {
|
||||
let allPassed: boolean;
|
||||
if (typeof styles === 'string') {
|
||||
allPassed = getDOM().hasStyle(actual, styles);
|
||||
allPassed = hasStyle(actual, styles);
|
||||
} else {
|
||||
allPassed = Object.keys(styles).length !== 0;
|
||||
Object.keys(styles).forEach(prop => {
|
||||
allPassed = allPassed && getDOM().hasStyle(actual, prop, styles[prop]);
|
||||
});
|
||||
Object.keys(styles).forEach(
|
||||
prop => { allPassed = allPassed && hasStyle(actual, prop, styles[prop]); });
|
||||
}
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user