Skip to content

tsconfig.spec.json types are not being resolved when opening testing files in VSCode #29239

@arkthur

Description

@arkthur

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

In an Angular project created by CLI, there are three tsconfig files: the base one, the app one and the tests (spec) one. Since Angular has been moving towards esbuild and Vite to build its apps, I'm trying Vitest to run its unit tests. For this, I'm using the integration made by Analog.js (https://analogjs.org/docs/features/testing/vitest).

Everything works fine testing-wise, but in VSCode, and after I removed every package related to any other test runner (karma and jasmine in this case), when I open any ´src/**/*.spec.ts´ file, there are error concerning typing not being resolved for every global testing function, like ´describe´, ´it´ or ´expect´, even though, and as per instructed, ´vitest/globals´ are being correctly referenced in the ´tsconfig.spec.json´.

When I open any testing file, aside of the errors, VSCode tells me the config file it's using to resolve this file is the base one (tsconfig.json). And, if I add ´vitest/globals´ to the base config, errors disappear.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-kgrhhncg

Please provide the exception or error you saw

Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha`. ts(2582)

Cannot find name 'beforeEach'.ts(2304)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.0.5
Node: 22.12.0
Package Manager: npm 10.9.0
OS: win32 x64

Angular: 19.0.4
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.7
@angular-devkit/build-angular   19.0.5
@angular-devkit/core            19.0.5
@angular-devkit/schematics      19.0.5
@angular/cdk                    19.0.3
@angular/cli                    19.0.5
@angular/material               19.0.3
@schematics/angular             19.0.5
rxjs                            7.8.1
typescript                      5.6.3

Anything else?

Note

I have doubts about this issue being Angular related. Maybe this is a TypeScript and/or VSCode error. Even so, this issue might be of the interest of the Angular team concerning the way ´tsconfig.json´ files are being used by VSCode to resolve its ts files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions