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
test.each's behaviour deviates from jest's #1858
Comments
Should we align with jest behavior? |
Jest's behaviour is exactly what I'd expect, even if I didn't know anything about Jest. What's the rationale for converting |
I am waiting for confirmation from core team. I think we should align to jest behavior. @sheremet-va |
let's align the behavior. |
Clarification of Jest's behaviour (v29.0.3). This wasn't entirely as expected. These tests pass: test.each([
null,
])('value is null', (value) => {
expect(value).toBeNull()
});
test.each([
[null, null],
[null, null],
])('if all cases are arrays of equal length, treats array elements as arguments', (value) => {
// typeof value: null
expect(value).toBeNull()
}) These tests fail: test.each([
null,
[null], // <-- FAIL: value is `[null]`
])('null value or null item is null', (value) => {
// typeof value: null | any[]
expect(value).toBeNull()
})
test.each([
[null], // <-- FAIL: value is `[null]`
null,
])('null value or null item is null', (value) => {
// typeof value: null | any[]
expect(value).toBeNull()
})
// ** FAIL: Test times out **
test.each([
[null],
[null, null],
])('if all cases are arrays, treats array elements as arguments', (value, _value?) => {
expect(value).toBeNull()
}) |
* fix(vitest) align .each behavior with jest close #1858 * chore: update Co-authored-by: golebiowskib <bartosz.golebiowski@@ttpsc.pl> Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Describe the bug
As noted previously in #1461, there are significant differences in
test.each()
betweenvitest
andjest
.Reproduction
test.each()
with an array containing null, e.g.test.each([null])
, the value will be processed as an array containing null ([null]
) on Jest and converted to anull
on Vitest.Vitest used to return an empty array in that scenario, but this was changed in #1462) and is enforced in this test:
https://github.com/vitest-dev/vitest/blob/main/test/core/test/each.test.ts#L11
However, the same test will fail in Jest:
undefined
in Vitest:On Jest, the output is:
On Vitrest, the output is:
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: