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

chore(jest): Fix Jest Deprecation Warnings #465

Merged
merged 4 commits into from
Feb 19, 2025
Merged

Conversation

hf-krechan
Copy link
Collaborator

@hf-krechan hf-krechan commented Feb 18, 2025

what is the difference between jest-preset-angular and ts-jest?

Let me explain the key differences between jest-preset-angular and ts-jest

ts-jest

  • A general-purpose Jest transformer for TypeScript files
  • Converts TypeScript code to JavaScript that Jest can understand
  • Provides basic TypeScript support for any Jest project
  • Doesn't have any framework-specific handling
  • Used as a foundation by many other testing presets

jest-preset-angular

  • Built specifically for testing Angular applications
  • Actually uses ts-jest under the hood, but adds Angular-specific functionality
  • Includes additional features like:
    • Proper handling of Angular templates and decorators
    • Built-in support for Angular's zone.js
    • Handling of Angular's dependency injection system
    • Support for Angular's template syntax
    • Proper transformation of Angular-specific files (like .html templates)
    • Preconfigured settings optimized for Angular testing
    • Handles Angular's module system and decorators correctly

In our configuration, using jest-preset-angular as the transformer is better because:

  1. It understands Angular-specific code patterns
  2. It handles Angular templates and modules correctly
  3. It comes with pre-configured settings that work well with Angular's ecosystem
  4. It includes the zone.js setup needed for Angular's change detection

That's why switching from ts-jest to jest-preset-angular in your configuration helped resolve the issues - it provides the complete Angular testing environment rather than just TypeScript compilation.

          Importing "setup-jest.js" directly is deprecated. The file "setup-jest.js" will be removed in the future.
          Please use "setupZoneTestEnv" function instead. Example:

          // setup-jest.ts
          import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';

          setupZoneTestEnv();
ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. Please do
transform: {
    <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},
See more at https://kulshekhar.github.io/ts-jest/docs/getting-started/presets#advanced
ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. Please do
transform: {
    <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},
@hf-krechan hf-krechan enabled auto-merge (squash) February 18, 2025 22:55
@hf-krechan hf-krechan linked an issue Feb 18, 2025 that may be closed by this pull request
Copy link
Contributor

@hf-kklein hf-kklein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@hf-krechan hf-krechan merged commit de0d859 into main Feb 19, 2025
4 checks passed
@hf-krechan hf-krechan deleted the fix-jest-warning branch February 19, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Testframework Jest Warnings
2 participants