You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Migrating tests from jest to Vitest, the way describe.each and it.each function is buggy. According to the jest docs, using describe.each or it.each should internally convert a single-dimensional array to a multidimensional array. For example, [1, 2, 0] would be converted to [[1], [2], [0]]. This is a very common scenario for simple tests.
Unfortunately, using the single-dimensional array syntax with Vitest v0.4.1, testing with [1, 2, 0] fails when running the test for 0 (numeric zero). It seems that the value gets converted to undefined!
I did find the comment in #640 indicating that template literal usage is intentionally left out, but it makes no mention of single-dimensional arrays, which I see as being far more common. If single-dimensional arrays are also being omitted, then I think the docs need to be updated to call out these differences.
Reproduction
[1,2,0].forEach((num)=>{it(`${num} is a number (foreach)`,()=>{expect(typeofnum).toEqual('number');});});it.each([1,2,0])('%s is a number (it.each 1d)',(num)=>{expect(typeofnum).toEqual('number');});it.each([[1],[2],[0],])('%s is a number (it.each 2d)',(num)=>{expect(typeofnum).toEqual('number');});describe.each([1,2,0])('%s (describe.each 1d)',(num)=>{it(`${num} is a number (describe.each 1d)`,()=>{expect(typeofnum).toEqual('number');});});describe.each([[1],[2],[0],])('%s (describe.each 2d)',(num)=>{it(`${num} is a number (describe.each 2d)`,()=>{expect(typeofnum).toEqual('number');});});
√ 1 is a number (foreach)
√ 2 is a number (foreach)
√ 0 is a number (foreach)
√ 1 is a number (it.each 1d)
√ 2 is a number (it.each 1d)
× %s is a number (it.each 1d)
√ 1 is a number (it.each 2d)
√ 2 is a number (it.each 2d)
√ 0 is a number (it.each 2d)
√ 1 (describe.each 1d) (1)
√ 2 (describe.each 1d) (1)
❯ %s (describe.each 1d) (1)
× undefined is a number (describe.each 1d)
√ 1 (describe.each 2d) (1)
√ 2 (describe.each 2d) (1)
√ 0 (describe.each 2d) (1)
Failing tests result in AssertionError: expected 'undefined' to deeply equal 'number'
Describe the bug
Migrating tests from jest to Vitest, the way
describe.each
andit.each
function is buggy. According to the jest docs, usingdescribe.each
orit.each
should internally convert a single-dimensional array to a multidimensional array. For example,[1, 2, 0]
would be converted to[[1], [2], [0]]
. This is a very common scenario for simple tests.Unfortunately, using the single-dimensional array syntax with Vitest v0.4.1, testing with
[1, 2, 0]
fails when running the test for0
(numeric zero). It seems that the value gets converted toundefined
!I did find the comment in #640 indicating that template literal usage is intentionally left out, but it makes no mention of single-dimensional arrays, which I see as being far more common. If single-dimensional arrays are also being omitted, then I think the docs need to be updated to call out these differences.
Reproduction
Failing tests result in
AssertionError: expected 'undefined' to deeply equal 'number'
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: