Let the test.each callback access the current case key
@Krinkle is already working on this.
Since Dec 21, 2024.
- Dominant language
- JavaScript
- Stars
- 4k
- Forks
- 773
- PR merge metrics
- No merged PRs in 30d
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.