You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use `QUnit.module.if()`, to conditionally skip an entire module. For example, if these tests are only meant to run in certain environments, operating systems, or when certain optional dependencies are installed.
259
+
Use `QUnit.module.if()`, to conditionally skip an entire module. For example, if these tests are only meant to run in certain environments, operating systems, or when certain optional dependencies are installed. See also [`QUnit.test.if()`](./test.if.md).
Copy file name to clipboardExpand all lines: docs/api/QUnit/test.if.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,16 +23,37 @@ If the condition is true, this is equivalent to calling [`QUnit.test()`](./test.
23
23
24
24
If the conditional is false, this is equivalent to calling [`QUnit.test.skip()`](./test.skip.md), and test will not run. Instead, it will be listed in the results as a "skipped" test.
25
25
26
-
As a codebase becomes bigger, you may need to conditionally skip an entire group of tests. You can use [`QUnit.module.if()`](./module.md) to recursively skip all tests in a module based on a given requirement.
26
+
Use cases:
27
+
* Skip tests for a feature not supported in an older browser, when cross-browser testing in CI.
28
+
* Skip tests for code that relies on an optional dependency.
29
+
* Skip tests for an optional integration on one operating system, when testing a cross-platform application on Linux, macOS, and Windows.
30
+
31
+
You can use [`QUnit.module.if()`](./module.md) to skip several tests or nested modules at once, without repeating the same condition.
27
32
28
33
## Examples
29
34
35
+
### Feature test
36
+
37
+
This is an example that automatically skips a test in environments where [WebGL](https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial) is unsupported. For example, if you do cross-browser testing in CI and support older browsers in your project, you can use this to cover optional features for newer browsers that are expected to fail in older browsers.
38
+
39
+
```js
40
+
QUnit.module('MyApp');
41
+
42
+
QUnit.test.if('drawCanvas [red square]', typeofWebGLRenderingContext!=='undefined', function (assert) {
43
+
constcanvas=MyApp.drawCanvas();
44
+
assert.pixelEqual(canvas, 10, 10, 255, 0, 0);
45
+
assert.pixelEqual(canvas, 20, 20, 255, 0, 0);
46
+
});
47
+
```
48
+
30
49
### Skip a test
31
50
51
+
This example is for a library that targets both browsers and Node.js, where this test is for a feature that is only meant to work in browsers, and naturally skipped when the test suite is run in Node.js.
52
+
32
53
```js
33
54
QUnit.module('MyApp');
34
55
35
-
//Skip if executed without a DOM
56
+
//Browser-only test, skipped if executed without a DOM
36
57
QUnit.test.if('render', typeofdocument!=='undefined', function (assert) {
0 commit comments