layout | title | excerpt | groups | redirect_from | version_added | ||||
---|---|---|---|---|---|---|---|---|---|
page-api |
QUnit.test.only() |
Add a test that is exclusively run. |
|
|
1.20.0 |
QUnit.test.only( name, callback )
QUnit.only( name, callback )
Add a test that is exclusively run, preventing other tests from running unless they are also defined in this way.
parameter | description |
---|---|
name (string) |
Title of unit being tested |
callback (function) |
Function that performs the test |
parameter | description |
---|---|
assert (object) |
A new instance object with the assertion methods |
Use this method to focus your test suite on specific tests. QUnit.test.only
will cause any other tests in your suite to be ignored.
This method is an alternative to re-running individual tests from the HTML reporter interface, and can be especially useful to set your filter upfront without first running the test suite in a browser, e.g. in a codebase with many long-running tests.
It can also be used as alternative to the --filter
CLI option. If you have a specific test in front of you in your text editor, you set the "only" flag on this test directly by using QUnit.test.only
, without needing to copy or otherwise match the test name via the --filter
option. Setting the "only" flag in this way, is similar to how you might use the debugger
keyword to interact with browser devtools.
When debugging a larger area of code, you may want to expand your filter to run all tests under a given module. You can useQUnit.module.only()
to automatically mark all tests inside that module as "only" tests.
| QUnit 2.12 | The QUnit.only()
method was renamed to QUnit.test.only()
.
Use of QUnit.only()
remains supported as an alias.
| QUnit 1.20 | The QUnit.only()
method was introduced.
How to use QUnit.test.only
to filter which tests are run.
QUnit.module('robot', hooks => {
let robot;
hooks.beforeEach(() => {
robot = new Robot();
});
QUnit.test('say()', assert => {
assert.true(robot.say('Hello'));
});
// Run only this test
// For example, you are working on changing this method.
QUnit.test.only('laser()', assert => {
assert.true(robot.laser());
});
QUnit.test('take()', assert => {
assert.true(robot.take(5));
});
});