Let the test.each callback access the current case key #1764
Open
Description
This is a feature request for QUnit.test.each
. I can do a PR if this is something you think is desirable to add.
Tell us about your runtime:
- QUnit version: 2.21.0
- Which environment are you using? (e.g., browser, Node): browser
- How are you running QUnit? (e.g., QUnit CLI, Grunt, Karma, manually in browser): Grunt and browser
What are you trying to do?
When using QUnit.test.each
it would sometimes be nice to have access to the test case key.
Code that reproduces the problem: for example notice the duplication here where both the status and the test case keys are the same:
QUnit.test.each('Test jobs in progress status', {
Running: {
status: 'Running',
expectedInProgress: true
},
Canceling: {
status: 'Canceling',
expectedInProgress: true
},
Canceled: {
status: 'Canceled',
expectedInProgress: false
}
}, function(assert, { status, expectedInProgress }) {
assert.equal(isInProgress(status), expectedInProgress);
});
What did you expect to happen?
I would expect to be able to write something like this:
QUnit.test.each('Test jobs in progress status', {
Running: true,
Canceling: true,
Canceled: false
}, function(assert, expectedInProgress, status) {
assert.equal(isInProgress(status), expectedInProgress);
});
where we get the test case key as an additional argument to the test callback.
What actually happened?
This is not possible yet, and we have to duplicate values to get nice reporting (instead of e.g. using an array where we just see integers as test case names).