Skip to content
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

fix: null inside test.each is not turned into an empty array #1462

Merged
merged 1 commit into from Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]
patak-dev marked this conversation as resolved.
Show resolved Hide resolved
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