refactor(schematics): use explicit jest imports in templates#2329
Closed
Generalsimus wants to merge 1 commit intonestjs:masterfrom
Closed
refactor(schematics): use explicit jest imports in templates#2329Generalsimus wants to merge 1 commit intonestjs:masterfrom
Generalsimus wants to merge 1 commit intonestjs:masterfrom
Conversation
Member
|
We're about to migrate to vitest in the next release #2302 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, when generating components using the Nest CLI (e.g.,
nest g resource), the generated.spec.tsfiles rely on implicit Jest global variables (describe,beforeEach,it,expect). The defaultpackage.jsonschematic also installs@types/jestto support this. This often results in type errors in test files right out of the box in strictly configured environments, as the dependencies are not explicitly declared.Issue Number: N/A
What is the new behavior?
The templates have been refactored to prioritize explicit dependencies:
package.jsonschematic now installs@jest/typesinstead of@types/jest..spec.tsfiles now include explicit imports at the top of the file (e.g.,import { describe, beforeEach, it, expect } from '@jest/globals';).This eliminates type errors in newly generated components and aligns the boilerplate with strict clean-code practices by avoiding global namespace pollution.
Does this PR introduce a breaking change?
Other information
This change only affects newly scaffolded files and projects. Existing tests using implicit globals will continue to work normally.