Jasmine has iit()
and ddescribe
, and Mocha has it.only
and describe.only
, but I can't see any way to get QUnit to focus on running a single test.
The QUnit UI allows you to run a single test, but I can't see how to get this to work inside Karma, because it doesn't display the QUnit UI.
Here is my solution. It works fine for me, but YMMV.
Download qunit-karma-setup.js, qunit-karma-launch.js from here
Then, in your Gruntfile:
config.set({
frameworks: ['qunit'],
files: [
'your-app-files-here/**/*.js',
'qunit-karma-setup.js',
'your-tests-here/**/*.js',
'qunit-karma-launch.js'
]
});
Now, you can use omodule(), otest(), oasyncTest() functions to run only the selected modules or tests respectively.
QUnit is not well designed for this, but you can improve it!
The filtering mechanism of QUnit is validTest
function that read QUnit.config.filter
(string, name of a test). See https://github.com/jquery/qunit/blob/master/src/core.js#L820
There are two problems:
- it only allows selecting one test,
- you need to know the selected test name in advance (because the tests are filtered when being created).
Suggest changing QUnit to:
- filter using a custom "filter" function (the default implementation can do what the current
validTest
does), - filter the tests when executing (means, collects all the tests first)
Then, implementing inclusive tests will be simple ;-)
Add this on the top of your test file
var ttest = test;
test = function() {}
And rename the test you want to run to ttest
. Looks clumsy, but simple and works well.
I believe you can use only
. Taken from the docs:
test('my test 1', function (assert) { ... });
only('my test that will be run exclusively now', function (assert) { ... });
So instead of using word test
, you use only
.
来源:https://stackoverflow.com/questions/18975998/is-it-possible-to-run-a-single-test-using-qunit-inside-karma