angular/packages/compiler/test/shadow_css/ng_deep_spec.ts
dario-piotrowicz 61023b563d refactor(compiler): refactor the shadow css specs (#48443)
apply different quality of life improvements to the shadow
css unit tests:

- refactor the tests so that they are nicely divided in multiple files
   in a logical manner instead of having most of them all in a single big file

- remove the css normalization logic inconsistently used throughout  the tests, which
  causes tests to be inconsistent and it also introduced unintuitive checks

- provide a shared shim utility function (instead of re-defining it
  multiple times)

- add a `toEqualCss` matcher that can be used in the tests in order to
  match css strings without caring about spacing and indentation

PR Close #48443
2023-01-11 14:55:52 -08:00

34 lines
1.1 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.io/license
*/
import {shim} from './utils';
describe('ShadowCss, ng-deep', () => {
it('should handle /deep/', () => {
const css = shim('x /deep/ y {}', 'contenta');
expect(css).toEqualCss('x[contenta] y {}');
});
it('should handle >>>', () => {
const css = shim('x >>> y {}', 'contenta');
expect(css).toEqualCss('x[contenta] y {}');
});
it('should handle ::ng-deep', () => {
let css = '::ng-deep y {}';
expect(shim(css, 'contenta')).toEqualCss('y {}');
css = 'x ::ng-deep y {}';
expect(shim(css, 'contenta')).toEqualCss('x[contenta] y {}');
css = ':host > ::ng-deep .x {}';
expect(shim(css, 'contenta', 'h')).toEqualCss('[h] > .x {}');
css = ':host ::ng-deep > .x {}';
expect(shim(css, 'contenta', 'h')).toEqualCss('[h] > .x {}');
css = ':host > ::ng-deep > .x {}';
expect(shim(css, 'contenta', 'h')).toEqualCss('[h] > > .x {}');
});
});