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

[Bug]: TS 5.2 - TypeError: toSorted is not a function #4204

Open
koni1234 opened this issue Sep 4, 2023 · 2 comments
Open

[Bug]: TS 5.2 - TypeError: toSorted is not a function #4204

koni1234 opened this issue Sep 4, 2023 · 2 comments

Comments

@koni1234
Copy link

koni1234 commented Sep 4, 2023

Version

29.1.1

Steps to reproduce

TS config:

{ "compilerOptions": { // ..., "target": "ES6", "module": "ESNext", "moduleResolution": "Node", "lib": ["ES2023", "DOM"], } }

Jest config:

{ preset: 'ts-jest', testEnvironment: 'jsdom', testEnvironmentOptions: { customExportConditions: ['node', 'node-addons'], }, setupFiles: ['<rootDir>/tests/unit/jest.init.ts'], transform: { '^.+\\.ts$': ['ts-jest', { isolatedModules: true }], // ... }, // ..., };

create a simple test like this one

describe('',() => { it('test toSorted', () => { expect([1, 3, 2].toSorted()).toStrictEqual([1, 2, 3]); }); });

Expected behavior

I should see the test passed

Actual behavior

Test fail with this error:

TypeError: [1,3,2].toSorted is not a function

Debug log

https://justpaste.it/ckwj8

Additional context

Typescript checks and build work fine, the problem seems to be present only in unit tests.

Environment

System:
    OS: macOS 13.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 18.14.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.3.1 - /usr/local/bin/npm
  npmPackages:
    jest: ^29.6.2 => 29.6.2
@koni1234 koni1234 changed the title [Bug]: TS 5.2 - TypeError: [1,3,2].toSorted is not a function [Bug]: TS 5.2 - TypeError: toSorted is not a function Sep 4, 2023
@koni1234
Copy link
Author

using Node v20.6.1 it works

@ValentinGurkov
Copy link

using Node v20.6.1 it works

Yes, toSorted is not available in Node 18. Not related to ts-jest.

See Array.prototype.toSorted() - Browser compatibility.

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