diff --git a/docs/guide/testing-types.md b/docs/guide/testing-types.md index ef8d6d76098c..e26abc1e86e1 100644 --- a/docs/guide/testing-types.md +++ b/docs/guide/testing-types.md @@ -14,7 +14,13 @@ Vitest allows you to write tests for your types, using `expectTypeOf` or `assert Under the hood Vitest calls `tsc` or `vue-tsc`, depending on your config, and parses results. Vitest will also print out type errors in your source code, if it finds any. You can disable it with [`typecheck.ignoreSourceErrors`](/config/#typecheck-ignoresourceerrors) config option. -Keep in mind that Vitest doesn't run or compile these files, they are only statically analyzed by the compiler, and because of that you cannot use any dynamic statements. Meaning, you cannot use dynamic test names, and `test.each`, `test.runIf`, `test.skipIf`, `test.concurrent` APIs. But you can use other APIs, like `test`, `describe`, `.only`, `.skip` and `.todo`. +Keep in mind that Vitest doesn't run these files, they are only statically analyzed by the compiler. Meaning, that if you use a dynamic name or `test.each` or `test.for`, the test name will not be evaluated - it will be displayed as is. + +::: warning +Before Vitest 2.1, your `typecheck.include` overrode the `include` pattern, so your runtime tests did not actually run; they were only type-checked. + +Since Vitest 2.1, if your `include` and `typecheck.include` overlap, Vitest will report type tests and runtime tests as separate entries. +::: Using CLI flags, like `--allowOnly` and `-t` are also supported for type checking. diff --git a/packages/vitest/src/typecheck/collect.ts b/packages/vitest/src/typecheck/collect.ts index 66a825997cd5..4d4ac20ec5b5 100644 --- a/packages/vitest/src/typecheck/collect.ts +++ b/packages/vitest/src/typecheck/collect.ts @@ -107,7 +107,7 @@ export async function collectTests( const property = callee?.property?.name const mode = !property || property === name ? 'run' : property // the test node for skipIf and runIf will be the next CallExpression - if (mode === 'each' || mode === 'skipIf' || mode === 'runIf') { + if (mode === 'each' || mode === 'skipIf' || mode === 'runIf' || mode === 'for') { return } diff --git a/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts b/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts index 769f096f230c..19d62fbd2865 100644 --- a/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts +++ b/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts @@ -1,6 +1,10 @@ import { expectTypeOf, test } from 'vitest' -test.each(['some-value'])('%s', () => { +test.each(['some-value'])('each: %s', () => { + expectTypeOf(1).toEqualTypeOf(2) +}) + +test.for(['some-value'])('for: %s', () => { expectTypeOf(1).toEqualTypeOf(2) }) diff --git a/test/typescript/test/runner.test.ts b/test/typescript/test/runner.test.ts index 4f83f14ca7f5..6d71947f33f8 100644 --- a/test/typescript/test/runner.test.ts +++ b/test/typescript/test/runner.test.ts @@ -114,12 +114,13 @@ describe('ignoreSourceErrors', () => { }) describe('when the title is dynamic', () => { - it('correctly works', async () => { + it('works correctly', async () => { const vitest = await runVitest({ root: resolve(__dirname, '../fixtures/dynamic-title'), }) - expect(vitest.stdout).toContain('✓ %s') + expect(vitest.stdout).toContain('✓ for: %s') + expect(vitest.stdout).toContain('✓ each: %s') expect(vitest.stdout).toContain('✓ dynamic skip') expect(vitest.stdout).not.toContain('✓ false') // .skipIf is not reported as a separate test expect(vitest.stdout).toContain('✓ template string')