Skip to content

Commit

Permalink
fix: null inside test.each is not turned into an empty array (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 10, 2022
1 parent 8cf498f commit 1660b59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/vitest/src/runtime/suite.ts
@@ -1,6 +1,6 @@
import { format } from 'util'
import type { File, RunMode, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, Test, TestAPI, TestFunction } from '../types'
import { isObject, noop, toArray } from '../utils'
import { isObject, noop } from '../utils'
import { createChainable } from './chain'
import { collectTask, collectorContext, createTestContext, runWithSuite, withTimeout } from './context'
import { getHooks, setFn, setHooks } from './map'
Expand Down Expand Up @@ -167,7 +167,7 @@ function createSuite() {
suite.each = <T>(cases: ReadonlyArray<T>) => {
return (name: string, fn: (...args: T[]) => void) => {
cases.forEach((i, idx) => {
const items = toArray(i) as any
const items = Array.isArray(i) ? i : [i]
suite(formatTitle(name, items, idx), () => fn(...items))
})
}
Expand Down Expand Up @@ -195,7 +195,7 @@ function createTest(fn: (
test.each = <T>(cases: ReadonlyArray<T>) => {
return (name: string, fn: (...args: T[]) => void) => {
cases.forEach((i, idx) => {
const items = toArray(i) as any
const items = Array.isArray(i) ? i : [i]
test(formatTitle(name, items, idx), () => fn(...items))
})
}
Expand Down
7 changes: 7 additions & 0 deletions test/core/test/each.test.ts
Expand Up @@ -8,6 +8,13 @@ test.each([
expect(a + b).toBe(expected)
})

test.each([
null,
[null],
])('null is null', (value) => {
expect(value).toBe(null)
})

test.each([
['string', true],
['string', false],
Expand Down

0 comments on commit 1660b59

Please sign in to comment.