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

Tests using @angular-builders/jest cannot import jest object from @jest/globals #28722

Open
1 task
Tommy228 opened this issue Oct 27, 2024 · 0 comments
Open
1 task

Comments

@Tommy228
Copy link

Tommy228 commented Oct 27, 2024

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Importing jest from @jest/globals with the new test builder fails with the error Do not import @jest/globals outside of the Jest test environment.

This isn't an issue when writing spec files as you can directly access it (probably thanks to this) or use import.meta.jest, however this breaks compatibility with third party libs such as Spectator.

Minimal Reproduction

import { jest } from '@jest/globals';

describe('test', () => {
  beforeEach(() => {
    jest.useFakeTimers();
  });
});

Exception or Error

 FAIL  dist/test-out/4c1de1b8-6e3e-4b2a-add2-968166a278d8/app.component.spec.mjs
  ● Test suite failed to run

    Do not import `@jest/globals` outside of the Jest test environment

      at node_modules/@jest/globals/build/index.js:11:7

Your Environment

Angular CLI: 18.2.9
Node: 22.10.0
Package Manager: npm 10.9.0
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.9
@angular-devkit/build-angular   18.2.9
@angular-devkit/core            18.2.9
@angular-devkit/schematics      18.2.9
@angular/cli                    18.2.9
@schematics/angular             18.2.9
rxjs                            7.8.1
typescript                      5.5.4
zone.js                         0.14.10

Anything else relevant?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants