Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide QUnit.test aliases for only/todo/skip #1496

Merged
merged 2 commits into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/QUnit/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ version_added: "1.0"
---

`QUnit.test( name, callback )`
`QUnit.test.only( name, callback )`<br>
`QUnit.test.skip( name, callback )`<br>
`QUnit.test.todo( name, callback )`

Add a test to run.

Expand All @@ -28,6 +31,12 @@ Add a test to run.
|-----------|-------------|
| `assert` (object) | A new instance object with the [assertion methods](../assert/index.md) |

The `only`, `skip`, and `todo` variants of `QUnit.test` are aliases to the respective main QUnit methods:<br>

* `QUnit.test.only()` is the same as [`QUnit.only()`](./only.md)
* `QUnit.test.skip()` is the same as [`QUnit.skip()`](./skip.md)
* `QUnit.test.todo()` is the same as [`QUnit.todo()`](./todo.md)

### Description

Add a test to run using `QUnit.test()`.
Expand Down
11 changes: 5 additions & 6 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import equiv from "./equiv";
import dump from "./dump";
import module from "./module";
import Assert from "./assert";
import Test, { test, skip, only, todo, pushFailure } from "./test";
import Test, { test, pushFailure } from "./test";
import exportQUnit from "./export";

import config from "./core/config";
Expand Down Expand Up @@ -43,11 +43,10 @@ extend( QUnit, {

test: test,

todo: todo,

skip: skip,

only: only,
// alias other test flavors for easy access
todo: test.todo,
skip: test.skip,
only: test.only,

start: function( count ) {
var globalStartAlreadyCalled = globalStartCalled;
Expand Down
68 changes: 33 additions & 35 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,48 +689,46 @@ export function test( testName, callback ) {
newTest.queue();
}

export function todo( testName, callback ) {
if ( focused ) {
return;
}
extend( test, {
todo: function todo( testName, callback ) {
if ( focused ) {
return;
}

const newTest = new Test( {
testName,
callback,
todo: true
} );
const newTest = new Test( {
testName,
callback,
todo: true
} );

newTest.queue();
}
newTest.queue();
},
skip: function skip( testName ) {
if ( focused ) {
return;
}

// Will be exposed as QUnit.skip
export function skip( testName ) {
if ( focused ) {
return;
}
const test = new Test( {
testName: testName,
skip: true
} );

const test = new Test( {
testName: testName,
skip: true
} );
test.queue();
},
only: function only( testName, callback ) {
if ( !focused ) {
config.queue.length = 0;
focused = true;
}

test.queue();
}
const newTest = new Test( {
testName: testName,
callback: callback
} );

// Will be exposed as QUnit.only
export function only( testName, callback ) {
if ( !focused ) {
config.queue.length = 0;
focused = true;
newTest.queue();
}

const newTest = new Test( {
testName: testName,
callback: callback
} );

newTest.queue();
}
} );

// Resets config.timeout with a new timeout duration.
export function resetTestTimeout( timeoutDuration ) {
Expand Down
9 changes: 9 additions & 0 deletions test/main/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ QUnit.test( "testForPush", function( assert ) {
assert.testForPush( 1, 1, "should be call pushResult" );
} );

QUnit.module( "aliases" );

[ "todo", "skip", "only" ].forEach( function( flavor ) {
QUnit.test( flavor, function( assert ) {
assert.true( QUnit.test[ flavor ] instanceof Function );
assert.equal( QUnit[ flavor ], QUnit.test[ flavor ] );
} );
} );

QUnit.module( "QUnit.skip", {
beforeEach: function( assert ) {

Expand Down