angular/packages/compiler/test/shadow_css/utils.ts
Joey Perrott 9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00

58 lines
1.6 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ShadowCss} from '@angular/compiler/src/shadow_css';
export function shim(css: string, contentAttr: string, hostAttr: string = '') {
const shadowCss = new ShadowCss();
return shadowCss.shimCssText(css, contentAttr, hostAttr);
}
const shadowCssMatchers: jasmine.CustomMatcherFactories = {
toEqualCss: function (): jasmine.CustomMatcher {
return {
compare: function (actual: string, expected: string): jasmine.CustomMatcherResult {
const actualCss = extractCssContent(actual);
const expectedCss = extractCssContent(expected);
const passes = actualCss === expectedCss;
return {
pass: passes,
message: passes
? 'CSS equals as expected'
: `Expected '${actualCss}' to equal '${expectedCss}'`,
};
},
};
},
};
function extractCssContent(css: string): string {
return css
.replace(/^\n\s+/, '')
.replace(/\n\s+$/, '')
.replace(/\s+/g, ' ')
.replace(/:\s/g, ':')
.replace(/ }/g, '}');
}
beforeEach(function () {
jasmine.addMatchers(shadowCssMatchers);
});
declare global {
module jasmine {
interface Matchers<T> {
/**
* Expect the actual css value to be equal to the expected css,
* for this comparison extra spacing and newlines are ignored so
* that only the core css content is being compared.
*/
toEqualCss(expected: string): void;
}
}
}