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]: Class extends value undefined is not a constructor or null #4566

Open
StoryDevOffical opened this issue Sep 30, 2024 · 2 comments
Open

Comments

@StoryDevOffical
Copy link

Version

^29.2.3

Steps to reproduce

https://github.com/StoryDevOffical/TsJestCircular.git

Expected behavior

i expect other-item.spec.ts test run without error.
There is not test in this spec, and it fails as soon as importing fixture from other-item.fixture.ts

Actual behavior

When i run other-item.spec.ts with Jest/ts-jest, it raises an error
"Class extends value undefined is not a constructor or null".
OtherItem extends Item
^

Debug log

PASS  src/tests/config-item-embellishment/config-item-embellishment.spec.ts
 PASS  src/tests/embellishment/embellishment.spec.ts
 FAIL  src/tests/other-item/other-item.spec.ts
  ● Test suite failed to run

    TypeError: Class extends value undefined is not a constructor or null

      1 | import { Item } from '../item/item';
      2 |
    > 3 | export class Embellishment extends Item {
        |                                    ^
      4 |   data: string = "data";
      5 |   constructor() {
      6 |     super();

      at Object.<anonymous> (src/embellishment/embellishment.ts:3:36)
      at Object.<anonymous> (src/config-item-embellishment/config-item-embellishment.ts:3:1)
      at Object.<anonymous> (src/item/item.ts:3:1)
      at Object.<anonymous> (src/other-item/other-item.ts:2:1)
      at Object.<anonymous> (src/tests/other-item/other-item.fixture.ts:2:1)
      at Object.<anonymous> (src/tests/other-item/other-item.spec.ts:2:1)

Test Suites: 1 failed, 2 passed, 3 total
Tests:       14 passed, 14 total
Snapshots:   0 total
Time:        3.892 s


npm run start

> circular-extends@1.0.0 start
> nodemon --watch 'src/index.ts' --exec 'ts-node -r tsconfig-paths/register src/index.ts'

[nodemon] 3.1.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): src/index.ts
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `ts-node -r tsconfig-paths/register src/index.ts`
otherItem {"config":{"_someEmbellishment":[{"data":"data"}]}}
[nodemon] clean exit - waiting for changes before restart

Additional context

Even if there is circular dependency in Object modelization : The code is compiling and running (npm run start).
So Typescript/Javascript handle my code.
I handle this circular by defining config to 'undefined' for Embellishment Item.

Here the object modelization.
Capture d’écran 2024-09-30 184503

Environment

System:
    OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
    CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
  Binaries:
    Node: 18.19.1 - ~/.nvm/versions/node/v18.19.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v18.19.1/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@StoryDevOffical
Copy link
Author

export TS_JEST_LOG=ts-jest.log
ts-jest.log

@StoryDevOffical
Copy link
Author

StoryDevOffical commented Oct 1, 2024

Using this mock, the test is running well.

jest.mock('../../embellishment/embellishment', () => ({
  Embellishment: jest.fn().mockImplementation(() => ({
    data: 'mocked data'
  })),
}));

But i don't want to mock, cause i have to test the Class-Transformer logic to construct a new object.

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

1 participant