@brightspace-ui/testing 0.34.2 → 0.35.1
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 +15 -2
- package/package.json +1 -1
- package/src/browser/reset.js +11 -2
package/README.md
CHANGED
|
@@ -102,6 +102,19 @@ If `lang` is set to Arabic (`ar`), the right-to-left option will automatically b
|
|
|
102
102
|
|
|
103
103
|
> **Note:** it's not recommended to use `language` configuration with [vdiff](#vdiff-testing) to solely test the correctness of translations. The [messageformat-validator](https://github.com/bearfriend/messageformat-validator) is a more efficient way to test translations.
|
|
104
104
|
|
|
105
|
+
#### Configuring the Media Type
|
|
106
|
+
|
|
107
|
+
By default, tests will run using the `screen` media type. To use a different media type, pass a `media` option to `fixture()`.
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
it('should work when printing', async() => {
|
|
111
|
+
const elem = await fixture(html`<my-elem></my-elem>`, {
|
|
112
|
+
media: 'print'
|
|
113
|
+
});
|
|
114
|
+
// do assertions
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
105
118
|
### Accessibility Testing with aXe
|
|
106
119
|
|
|
107
120
|
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.
|
|
@@ -296,7 +309,7 @@ await waitUntil(() => elem.condition, {
|
|
|
296
309
|
If a test requires a one-off custom element, define it using `defineCE` and pass the returned tag name to `fixture()`.
|
|
297
310
|
|
|
298
311
|
```javascript
|
|
299
|
-
import { defineCE, fixture
|
|
312
|
+
import { defineCE, fixture } from '@brightspace-ui/testing';
|
|
300
313
|
|
|
301
314
|
const tag = defineCE(
|
|
302
315
|
class extends LitElement {
|
|
@@ -311,7 +324,7 @@ const tag = defineCE(
|
|
|
311
324
|
|
|
312
325
|
it('should use custom element', async() => {
|
|
313
326
|
const foo = 'bar';
|
|
314
|
-
const elem = await fixture(
|
|
327
|
+
const elem = await fixture(`<${tag} foo="${foo}"></${tag}>`);
|
|
315
328
|
});
|
|
316
329
|
```
|
|
317
330
|
|
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": "0.
|
|
5
|
+
"version": "0.35.1",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/testing.git",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"lint": "eslint . --ext .js",
|
package/src/browser/reset.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { sendMouse, setViewport } from '@web/test-runner-commands';
|
|
1
|
+
import { emulateMedia, sendMouse, setViewport } from '@web/test-runner-commands';
|
|
2
2
|
import { getDocumentLocaleSettings } from '@brightspace-ui/intl/lib/common.js';
|
|
3
3
|
import { nextFrame } from '@open-wc/testing';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_FULLSCREEN = false,
|
|
6
6
|
DEFAULT_LANG = 'en',
|
|
7
7
|
DEFAULT_MATHJAX_RENDER_LATEX = false,
|
|
8
|
+
DEFAULT_MEDIA = 'screen',
|
|
8
9
|
DEFAULT_VIEWPORT_HEIGHT = 800,
|
|
9
10
|
DEFAULT_VIEWPORT_WIDTH = 800;
|
|
10
11
|
|
|
@@ -13,6 +14,7 @@ const documentLocaleSettings = getDocumentLocaleSettings();
|
|
|
13
14
|
let
|
|
14
15
|
currentFullscreen = false,
|
|
15
16
|
currentMathjaxRenderLatex = DEFAULT_MATHJAX_RENDER_LATEX,
|
|
17
|
+
currentMedia = DEFAULT_MEDIA,
|
|
16
18
|
currentRtl = false,
|
|
17
19
|
currentViewportHeight = 0,
|
|
18
20
|
currentViewportWidth = 0,
|
|
@@ -32,7 +34,8 @@ export async function reset(opts = {}) {
|
|
|
32
34
|
height: DEFAULT_VIEWPORT_HEIGHT,
|
|
33
35
|
width: DEFAULT_VIEWPORT_WIDTH
|
|
34
36
|
},
|
|
35
|
-
fullscreen: DEFAULT_FULLSCREEN
|
|
37
|
+
fullscreen: DEFAULT_FULLSCREEN,
|
|
38
|
+
media: DEFAULT_MEDIA
|
|
36
39
|
};
|
|
37
40
|
|
|
38
41
|
opts = { ...defaultOpts, ...opts };
|
|
@@ -98,6 +101,12 @@ export async function reset(opts = {}) {
|
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
if (opts.media !== currentMedia) {
|
|
105
|
+
currentMedia = opts.media;
|
|
106
|
+
await emulateMedia({ media: opts.media }).catch(() => {});
|
|
107
|
+
awaitNextFrame = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
101
110
|
if (awaitNextFrame) {
|
|
102
111
|
await nextFrame();
|
|
103
112
|
}
|