teambit / bit

A build system for development of composable software.

Home Page:https://bit.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ReferenceError: jest is not defined

scrodrig opened this issue · comments

Describe the bug

When using a node module component:

$ bit create module modules/hello-world

Steps to Reproduce

const foo= {
  bar: (a, b) => a + b,
};
 describe('fake api', () => {
      beforeEach(() => {
        jest.restoreAllMocks();
      });

      it('renders with the correct text', () => {
             const spy = jest.spyOn(foo, 'bar');
              expect(spy).toHaveBeenCalled();
        });
});

Expected Behavior

This should work and pass the test

Screenshots, exceptions and logs

The issue is that structures as it, describe, equal and so on ... works with no issue,
but when trying to use jest.spyOn or jest.restoreAllMocks(), I got:

ReferenceError: jest is not defined

Specifications

  • Bit version: 1.6.106
  • Workspace type: harmony
  • Node version: 20.12.0
  • npm version: 10.5.0
  • Platform: WSL2 Ubuntu 22.04

for harmony workspace

  • relevant env: bitdev.node/node-env@1.0.26
  • relevant aspects:
aspects
teambit.component/dev-files
teambit.compositions/compositions
teambit.dependencies/dependency-resolve
teambit.docs/docs
teambit.envs/envs
teambit.harmony/application
teambit.pkg/pkg
teambit.preview/preview
teambit.semantics/schema

for leagacy

  • Bit compiler (include version):
  • Bit tester (include version):

Additional context

I tried to instal jest by myself, but @bitdev/node.node-env@1.0.26 is already provided with that installation, also install bit install @jest/globals with no luck

the version of the env (1.0.26) is using Vitest, not Jest...
so this is the reason for your issue. if you want, you can replace the tester with Jest by creating a custom env.