Skip to content

[Bug]: Class extends value undefined is not a constructor or null #4566

@StoryDevOffical

Description

@StoryDevOffical

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions