Skip to content

Commit a8794d3

Browse files
committed
feat(testing-library__dom): monkey patched testing-library__dom mirror
1 parent 73be07f commit a8794d3

File tree

11 files changed

+720
-39
lines changed

11 files changed

+720
-39
lines changed

karma.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = (config) => {
3232
'packages/*/stories/*',
3333
'packages/icons-ui/*',
3434
'packages/icons-workflow/*',
35+
'projects/**/*',
3536
],
3637
},
3738
browsers: ['FirefoxHeadlessCustom'],

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"prelerna-publish": "yarn get-ready && yarn custom-element-json",
6060
"lerna-publish": "lerna publish --message 'chore: release new versions'",
6161
"test": "yarn build && yarn test:ci",
62-
"test:build": "tsc --build test/tsconfig-test.json",
62+
"test:build": "tsc --build test/tsconfig-test.json && lerna exec --scope testing-library__dom -- yarn build",
6363
"test:ci": "yarn test:build && karma start --coverage",
6464
"test:start": "karma start",
6565
"test:watch": "run-p watch 'test:build -w' 'test:start --auto-watch=true --single-run=false'",

packages/actionbar/test/actionbar.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { fixture, elementUpdated, html, expect } from '@open-wc/testing';
1414
import '../sp-actionbar.js';
1515
import { Actionbar } from '../';
1616
import { Default } from '../stories/actionbar.stories';
17+
import { getByLabelText } from 'testing-library__dom';
1718

1819
describe('Actionbar', () => {
1920
it('loads', async () => {
@@ -24,6 +25,8 @@ describe('Actionbar', () => {
2425
expect(el).to.not.be.undefined;
2526

2627
await expect(el).to.be.accessible();
28+
const input = getByLabelText(el, 'Edit');
29+
expect(input).to.not.be.undefined;
2730
});
2831

2932
it('accepts variants', async () => {

packages/sidenav/test/sidenav-item.test.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ governing permissions and limitations under the License.
1313
import '../sp-sidenav-item.js';
1414
import { SideNavItem } from '../';
1515
import { fixture, elementUpdated, html, expect } from '@open-wc/testing';
16+
import { getByText, queryByText } from 'testing-library__dom';
1617

1718
describe('Sidenav Item', () => {
1819
it('can exist disabled and with no parent', async () => {
@@ -68,29 +69,31 @@ describe('Sidenav Item', () => {
6869

6970
await elementUpdated(el);
7071

71-
expect(el.shadowRoot).to.exist;
72-
if (!el.shadowRoot) return;
73-
74-
let slot: HTMLSlotElement | null = el.shadowRoot.querySelector(
75-
'slot:not([name])'
76-
);
77-
expect(slot).not.to.exist;
72+
let section1 = queryByText(el, 'Section 1');
73+
let section2 = queryByText(el, 'Section 2');
7874

7975
expect(el.expanded).to.be.false;
76+
expect(section1, 'section 1: closed initial').to.be.null;
77+
expect(section2, 'section 2: closed initial').to.be.null;
8078

8179
el.click();
82-
8380
await elementUpdated(el);
8481

8582
expect(el.expanded).to.be.true;
83+
section1 = getByText(el, 'Section 1');
84+
section2 = getByText(el, 'Section 2');
85+
expect(section1, 'section 1: opened').to.not.be.null;
86+
expect(section2, 'section 2: opened').to.not.be.null;
8687

87-
slot = el.shadowRoot.querySelector(
88-
'slot:not([name])'
89-
) as HTMLSlotElement;
90-
expect(slot).to.exist;
91-
if (!slot) return;
88+
el.click();
89+
await elementUpdated(el);
90+
91+
section1 = queryByText(el, 'Section 1');
92+
section2 = queryByText(el, 'Section 2');
9293

93-
expect(slot.assignedElements().length).to.equal(2);
94+
expect(el.expanded).to.be.false;
95+
expect(section1, 'section 1: closed').to.be.null;
96+
expect(section2, 'section 2: closed').to.be.null;
9497
});
9598

9699
it('populated `aria-current`', async () => {
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dom.js

projects/testing-library__dom/README.md

Whitespace-only changes.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// TypeScript Version: 2.8
2+
export * from '@testing-library/dom';
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HTMLElement.prototype.querySelectorAllWithShadowDOM = function(query) {
2+
const isNotCustomElementParent = this.tagName.search('-') === -1;
3+
const children = [...(this.children || [])].filter(
4+
(child) => isNotCustomElementParent || !!child.assignedSlot
5+
);
6+
let results = children.filter((el) => el.matches(query));
7+
if (this.shadowRoot) {
8+
results = results.concat([
9+
...(this.shadowRoot.querySelectorAllWithShadowDOM(query) || []),
10+
]);
11+
}
12+
children.map((child) => {
13+
if (child.querySelectorAllWithShadowDOM) {
14+
results = results.concat([
15+
...(child.querySelectorAllWithShadowDOM(query) || []),
16+
]);
17+
}
18+
});
19+
return results;
20+
};
21+
22+
ShadowRoot.prototype.querySelectorAllWithShadowDOM = function(query) {
23+
const children = [...(this.children || [])];
24+
let results = children.filter((el) => el.matches(query));
25+
children.map((child) => {
26+
results = results.concat([
27+
...(child.querySelectorAllWithShadowDOM(query) || []),
28+
]);
29+
});
30+
return results;
31+
};
32+
33+
export * from './dom.js';
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "testing-library__dom",
3+
"version": "7.20.1",
4+
"description": "mirror of @testing-library/dom, bundled and exposed as ES module",
5+
"author": "",
6+
"main": "index.js",
7+
"publishConfig": {
8+
"access": "public"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/bundled-es-modules/testing-library-dom.git"
13+
},
14+
"license": "Apache-2.0",
15+
"devDependencies": {
16+
"@rollup/plugin-alias": "^2.2.0",
17+
"@rollup/plugin-replace": "^2.2.1",
18+
"@testing-library/dom": "^7.20.1",
19+
"babel-core": "^6.26.3",
20+
"core-js": "^2.5.7",
21+
"rollup": "^1.0.0",
22+
"rollup-plugin-commonjs": "^9.0.0",
23+
"rollup-plugin-copy": "^3.0.0",
24+
"rollup-plugin-ignore": "^1.0.5",
25+
"rollup-plugin-node-builtins": "^2.1.2",
26+
"rollup-plugin-node-globals": "^1.4.0",
27+
"rollup-plugin-node-resolve": "^4.0.0",
28+
"rollup-plugin-replace": "^2.1.0",
29+
"semver": ">=4.3.2"
30+
},
31+
"scripts": {
32+
"build": "rollup -c ./rollup.config.js"
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import resolve from 'rollup-plugin-node-resolve';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import replace from '@rollup/plugin-replace';
4+
5+
export default [
6+
{
7+
input: require.resolve(
8+
'@testing-library/dom/dist/@testing-library/dom.esm.js'
9+
),
10+
output: {
11+
file: './dom.js',
12+
format: 'es',
13+
},
14+
plugins: [
15+
resolve({
16+
browser: true,
17+
preferBuiltins: false,
18+
}),
19+
commonjs(),
20+
replace({
21+
querySelectorAll: 'querySelectorAllWithShadowDOM',
22+
}),
23+
],
24+
},
25+
];

0 commit comments

Comments
 (0)