angular/packages/compiler/test/shadow_css/utils.ts
Kristiyan Kostadinov d9c980a958 build: initial test of TypeScript 6
Resolves some initial test failures after updating to TypeScript 6.
2026-01-15 13:41:01 -08: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 '../../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 {
namespace 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;
}
}
}