ts-jest icon indicating copy to clipboard operation
ts-jest copied to clipboard

[Bug]: Import issue when using "Satisfies" keyword

Open ajubin opened this issue 1 year ago • 11 comments

Version

29.1.0

Steps to reproduce

My repository is private, I tried to reproduce on an example repo but I couldn't.

My bug is the following, I have 3 files

aFunction.spec.ts // testing aFunction.ts
aFunction.ts // importing model.ts
model.ts 

With the following content

// in aFunction.spec.ts
import { aFunction } from './aFunction';

test('bug class undefined when using satisifies', () => {
  const method = aFunction(['a']);
  expect(() => method).toThrow();
});


// in aFunction.ts
import { create, ReturnType } from './model';

export function aFunction(names: string[] | undefined) {
  return {
    experiences: names?.map((name) =>
      create({
        name: name,
      }),
    ),
  } satisfies ReturnType;
}


// in model.ts
interface Props {
  name: string;
}
export type ReturnType = {
  experiences?: Props[];
};

export function create(props: Props) {
  return { name: props.name };
}

When I run yarn jest I've got the following error ReferenceError: model_1 is not defined

But the error disappear in one of the following cases:

  • When I remove satisfies ReturnType in aFunction.ts
  • When I first create const experiences = names?.map(...) and then returns return {experiences} satisfies ReturnType
  • When I remove isolatedModules: true in my jest.config.ts

Expected behavior

imports from 'model' are indeed imported

Actual behavior

ReferenceError

Debug log

ts-jest.log

Additional context

// Jest.config.ts

import type { Config } from '@jest/types';

export default async (): Promise<Config.InitialOptions> => {
  return {
    moduleFileExtensions: ['js', 'json', 'ts'],
    rootDir: 'src',
    testRegex: '(?<!e2e|matching).spec.ts$',
    transform: {
      '^.+\\.(t|j)s$': [
        'ts-jest',
        {
          isolatedModules: true, // The following line improves perf : https://huafu.github.io/ts-jest/user/config/isolatedModules
        },
      ],
    },
 }
}

maybe useful packages version

  • "ts-node": "^10.9.1",
  • "typescript": "^4.9.3"
  • "jest": "^29.3.1"
  • "ts-jest": "^29.1.0",

Environment

System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 18.9.0 - /var/folders/rb/7gpds4dj163b0g71gyr42brh0000gn/T/fnm_multishells/20546_1681215510586/bin/node
    Yarn: 1.22.19 - /var/folders/rb/7gpds4dj163b0g71gyr42brh0000gn/T/fnm_multishells/20546_1681215510586/bin/yarn
    npm: 8.19.2 - /var/folders/rb/7gpds4dj163b0g71gyr42brh0000gn/T/fnm_multishells/20546_1681215510586/bin/npm
  npmPackages:
    jest: ^29.3.1 => 29.3.1

ajubin avatar Apr 17 '23 15:04 ajubin

Having the same issue. Jest explicitly calls out not recognizing satisfies from typescript. Removing satisfies runs the test correctly.

} satisfies Color);
      ^^^^^^^^^

    SyntaxError: Unexpected identifier

tfmertz-aw avatar Jun 22 '23 19:06 tfmertz-aw

Hitting this same issue 😄 Need any help moving this along?

bvaughn avatar Jun 29 '23 00:06 bvaughn

Having the same issue. Any updates on this? It mentions in the changelog that v29.1.0 supports Typescript 5.x

alainfonhof avatar Jul 11 '23 08:07 alainfonhof

same issue with jest" 29.5.0, any updates?

onivue avatar Aug 09 '23 06:08 onivue

Same here. Jest 29.5.0, typescript 4.9.5

Slate245 avatar Aug 28 '23 06:08 Slate245

Same here. Bummer that this has been an issue for 5 months.

Typescript: 5.0.4 ts-jest: 29.1.1 jest: 29.6.2

jordanmnunez avatar Sep 15 '23 16:09 jordanmnunez

It's quite impressive how it can't go along with TypeScript changes.

Any ideas how to handle that? My code is more safe with satisfies than with unit tests, but still need to make coverage target :skull:

KubaZachacz avatar Sep 25 '23 08:09 KubaZachacz

Same here it's been around one year now with no update from the team. satisfies is widely used by now, and still no support from ts-jest

JohnBerd avatar Apr 11 '24 21:04 JohnBerd

I don't know what the difficulties are in integrating the management of the satisfies operator into ts-jest. But it's a bit complicated not to be able to use a widely used typescript operator because the tests don't support it… Could we know why this is not integrated yet? What technical difficulties are you encountering?

hjumeau avatar Jun 10 '24 10:06 hjumeau

I don't see the Reference Error anymore. Does anyone have reproduce repo for this?

ahnpnl avatar Jul 10 '24 00:07 ahnpnl

@ahnpnl ya, I have no idea what changed when but I am able to use satisfies now.

jordanmnunez avatar Jul 10 '24 03:07 jordanmnunez