From c131b89ec589cbd21334e482ecf57e3f5a9c996d Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Fri, 10 Jun 2022 17:18:56 +0300 Subject: [PATCH] fix: null inside test.each is not turned into an empty array --- packages/vitest/src/runtime/suite.ts | 6 +++--- test/core/test/each.test.ts | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/vitest/src/runtime/suite.ts b/packages/vitest/src/runtime/suite.ts index b309dacc5eba..99d8b394339e 100644 --- a/packages/vitest/src/runtime/suite.ts +++ b/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' @@ -167,7 +167,7 @@ function createSuite() { suite.each = (cases: ReadonlyArray) => { 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)) }) } @@ -195,7 +195,7 @@ function createTest(fn: ( test.each = (cases: ReadonlyArray) => { 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)) }) } diff --git a/test/core/test/each.test.ts b/test/core/test/each.test.ts index b9a44f87ac18..8b38517e919a 100644 --- a/test/core/test/each.test.ts +++ b/test/core/test/each.test.ts @@ -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],