Skip to content

Commit 2555abb

Browse files
committed
exclude shadow dom tests on browsers that don't support it
1 parent 3a755f3 commit 2555abb

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

src/cdk/testing/tests/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ng_module(
1515
assets = glob(["**/*.html"]),
1616
deps = [
1717
"//src/cdk/keycodes",
18+
"//src/cdk/platform",
1819
"@npm//@angular/forms",
1920
],
2021
)
@@ -36,6 +37,7 @@ ng_test_library(
3637
deps = [
3738
":test_components",
3839
":test_harnesses",
40+
"//src/cdk/platform",
3941
"//src/cdk/testing",
4042
"//src/cdk/testing/private",
4143
"//src/cdk/testing/testbed",

src/cdk/testing/tests/test-main-component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h1 style="height: 100px; width: 200px;">Main Component</h1>
3232
</button>
3333
<span id="task-state-result" #taskStateResult></span>
3434
</div>
35-
<test-shadow-boundary>
35+
<test-shadow-boundary *ngIf="_shadowDomSupported">
3636
<div class="in-the-shadows">Shadow 1</div>
3737
<test-shadow-boundary>
3838
<div class="in-the-shadows">Shadow 2</div>

src/cdk/testing/tests/test-main-component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {ENTER} from '@angular/cdk/keycodes';
10+
import {_supportsShadowDom} from '@angular/cdk/platform';
1011
import {
1112
ChangeDetectionStrategy,
1213
ChangeDetectorRef,
@@ -42,6 +43,7 @@ export class TestMainComponent implements OnDestroy {
4243
specialKey = '';
4344
relativeX = 0;
4445
relativeY = 0;
46+
_shadowDomSupported = _supportsShadowDom();
4547

4648
@ViewChild('clickTestElement') clickTestElement: ElementRef<HTMLElement>;
4749
@ViewChild('taskStateResult') taskStateResultElement: ElementRef<HTMLElement>;

src/cdk/testing/tests/testbed.spec.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {_supportsShadowDom} from '@angular/cdk/platform';
12
import {
23
ComponentHarness,
34
ComponentHarnessConstructor,
@@ -7,12 +8,12 @@ import {
78
import {expectAsyncError} from '@angular/cdk/testing/private';
89
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
910
import {async, ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
11+
import {querySelectorAll as piercingQuerySelectorAll} from 'kagekiri';
1012
import {FakeOverlayHarness} from './harnesses/fake-overlay-harness';
1113
import {MainComponentHarness} from './harnesses/main-component-harness';
1214
import {SubComponentHarness, SubComponentSpecialHarness} from './harnesses/sub-component-harness';
1315
import {TestComponentsModule} from './test-components-module';
1416
import {TestMainComponent} from './test-main-component';
15-
import {querySelectorAll as piercingQuerySelectorAll} from 'kagekiri';
1617

1718
function activeElementText() {
1819
return document.activeElement && (document.activeElement as HTMLElement).innerText || '';
@@ -494,26 +495,28 @@ describe('TestbedHarnessEnvironment', () => {
494495
});
495496
});
496497

497-
describe('shadow DOM interaction', () => {
498-
it('should not pierce shadow boundary by default', async () => {
499-
const harness = await TestbedHarnessEnvironment
500-
.harnessForFixture(fixture, MainComponentHarness);
501-
expect(await harness.shadows()).toEqual([]);
502-
});
503-
504-
it('should pierce shadow boundary when using piercing query', async () => {
505-
const harness = await TestbedHarnessEnvironment
506-
.harnessForFixture(fixture, MainComponentHarness, piercingQuerySelectorAll);
507-
const shadows = await harness.shadows();
508-
expect(await Promise.all(shadows.map(el => el.text()))).toEqual(['Shadow 1', 'Shadow 2']);
498+
if (_supportsShadowDom()) {
499+
describe('shadow DOM interaction', () => {
500+
it('should not pierce shadow boundary by default', async () => {
501+
const harness = await TestbedHarnessEnvironment
502+
.harnessForFixture(fixture, MainComponentHarness);
503+
expect(await harness.shadows()).toEqual([]);
504+
});
505+
506+
it('should pierce shadow boundary when using piercing query', async () => {
507+
const harness = await TestbedHarnessEnvironment
508+
.harnessForFixture(fixture, MainComponentHarness, piercingQuerySelectorAll);
509+
const shadows = await harness.shadows();
510+
expect(await Promise.all(shadows.map(el => el.text()))).toEqual(['Shadow 1', 'Shadow 2']);
511+
});
512+
513+
it('should allow querying across shadow boundary', async () => {
514+
const harness = await TestbedHarnessEnvironment
515+
.harnessForFixture(fixture, MainComponentHarness, piercingQuerySelectorAll);
516+
expect(await (await harness.deepShadow()).text()).toBe('Shadow 2');
517+
});
509518
});
510-
511-
it('should allow querying across shadow boundary', async () => {
512-
const harness = await TestbedHarnessEnvironment
513-
.harnessForFixture(fixture, MainComponentHarness, piercingQuerySelectorAll);
514-
expect(await (await harness.deepShadow()).text()).toBe('Shadow 2');
515-
});
516-
});
519+
}
517520
});
518521

519522
async function checkIsElement(result: ComponentHarness | TestElement, selector?: string) {

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8983,7 +8983,7 @@ postcss-selector-parser@^3.1.0:
89838983
indexes-of "^1.0.1"
89848984
uniq "^1.0.1"
89858985

8986-
"postcss-selector-parser@github:nolanlawson/postcss-selector-parser#util-deprecate":
8986+
postcss-selector-parser@nolanlawson/postcss-selector-parser#util-deprecate:
89878987
version "6.0.2"
89888988
resolved "https://codeload.github.com/nolanlawson/postcss-selector-parser/tar.gz/75e38f7a7db8d58fb033ab7d24414b55d81e5b4f"
89898989
dependencies:

0 commit comments

Comments
 (0)