@brightspace-ui/testing 1.44.2 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -2
- package/package.json +1 -1
- package/src/browser/fixture.js +6 -6
- package/src/browser/index.js +1 -1
package/README.md
CHANGED
|
@@ -139,9 +139,9 @@ it('should work when printing', async() => {
|
|
|
139
139
|
});
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
### Accessibility Testing with
|
|
142
|
+
### Accessibility Testing with axe
|
|
143
143
|
|
|
144
|
-
Elements can be processed by the [
|
|
144
|
+
Elements can be processed by the [axe accessibility validator](https://github.com/dequelabs/axe-core), which will automatically fail the test if any violations are detected.
|
|
145
145
|
|
|
146
146
|
```javascript
|
|
147
147
|
it('should be accessible', async() => {
|
|
@@ -302,6 +302,20 @@ it('should wait for updates', async() => {
|
|
|
302
302
|
});
|
|
303
303
|
```
|
|
304
304
|
|
|
305
|
+
If that change causes a different set of nested components to be rendered, and those nested components take some time to finish *their* rendering, it's possible that awaiting `updateComplete` isn't enough.
|
|
306
|
+
|
|
307
|
+
In this case, `waitForElem` can be used to recursively wait in a similar way to the original `fixture` call:
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
import { fixture, waitForElem } from '@brightspace-ui/testing';
|
|
311
|
+
|
|
312
|
+
it('should wait for recursive re-rendering', async() => {
|
|
313
|
+
const elem = await fixture(html`<my-elem></my-elem>`);
|
|
314
|
+
elem.errorState = true;
|
|
315
|
+
await waitForElem(elem);
|
|
316
|
+
});
|
|
317
|
+
```
|
|
318
|
+
|
|
305
319
|
#### Waiting for `setTimeout` or `requestAnimationFrame`
|
|
306
320
|
|
|
307
321
|
To wait a fixed amount of time (analogous to `setTimeout`), use `aTimeout`. To wait until the moment before browser repaints the screen (analogous to `requestAnimationFrame`), use `nextFrame`.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@brightspace-ui/testing",
|
|
3
3
|
"description": "Utilities for testing front-end components and applications",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.45.0",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/testing.git",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "npm run lint:eslint && npm run lint:style",
|
package/src/browser/fixture.js
CHANGED
|
@@ -36,20 +36,20 @@ function getComposedChildren(node) {
|
|
|
36
36
|
* @param {*} elem
|
|
37
37
|
* @param {boolean} awaitLoadingComplete
|
|
38
38
|
*/
|
|
39
|
-
async function waitForElem(elem, awaitLoadingComplete = true) {
|
|
39
|
+
export async function waitForElem(elem, awaitLoadingComplete = true) {
|
|
40
40
|
|
|
41
41
|
if (!elem) return;
|
|
42
42
|
|
|
43
43
|
const doWait = async() => {
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
await update;
|
|
45
|
+
if (awaitLoadingComplete && typeof elem.getLoadingComplete === 'function') {
|
|
46
|
+
await elem.getLoadingComplete();
|
|
48
47
|
await nextFrame();
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const update = elem.updateComplete;
|
|
51
|
+
if (typeof update === 'object' && Promise.resolve(update) === update) {
|
|
52
|
+
await update;
|
|
53
53
|
await nextFrame();
|
|
54
54
|
}
|
|
55
55
|
|
package/src/browser/index.js
CHANGED
|
@@ -3,5 +3,5 @@ import './axe.js';
|
|
|
3
3
|
|
|
4
4
|
export { assert, aTimeout, defineCE, expect, html, nextFrame, oneDefaultPreventedEvent, oneEvent, waitUntil } from '@open-wc/testing';
|
|
5
5
|
export { clickAt, clickElem, clickElemAt, dragDropElems, focusElem, hoverAt, hoverElem, hoverElemAt, sendKeys, sendKeysElem, setViewport } from './commands.js';
|
|
6
|
-
export { fixture } from './fixture.js';
|
|
6
|
+
export { fixture, waitForElem } from './fixture.js';
|
|
7
7
|
export { runConstructor } from './constructor.js';
|