Skip to content

expect(object).toBeUndefined causes memory leak #9329

@MolSnoo

Description

@MolSnoo

Describe the bug

Expecting an object to be undefined causes a memory leak that results in the test executing infinitely until the heap runs out of memory. This happens regardless of whether expect(object).toBeUndefined() or expect(object).toBe(undefined) is called.

Reproduction

Code: https://github.com/LavCorps/Alter-Ego/blob/1937ee589d1855d6dafa43a1369bad43cf539c2f/Test/Classes/GameEntityFinder.test.js#L161

Job results: https://github.com/MolSnoo/Alter-Ego/actions/runs/20444377929/job/58744499257 (This happens on the machines of all users running this locally as well)

The test itself is actually incorrect here, as the function does return a value, but that shouldn't cause a memory leak.

EDIT: Upon further inspection, I suspect it has to do with pretty-format attempting to display circular references, as RoomItem contains a reference to Game, which itself contains references to RoomItems, and so on. This has been mended in newer commits to make game a private field accessible with a getter, but I imagine pretty-format being unable to display circular references without looping infinitely will be a problem for others.

System Info

System:
    OS: Linux 6.17 Fedora Linux 43 (KDE Plasma Desktop Edition)
    CPU: (12) x64 AMD Ryzen 5 7600X3D 6-Core Processor
    Memory: 17.63 GB / 30.43 GB
    Container: Yes
    Shell: 5.3.0 - /bin/bash
  Binaries:
    Node: 22.20.0 - /usr/bin/node
    npm: 10.9.3 - /usr/bin/npm
  Browsers:
    Firefox: 146.0
    Firefox Developer Edition: 146.0
  npmPackages:
    @vitest/coverage-v8: 4.0.15 => 4.0.16 
    vitest: 4.0.15 => 4.0.16

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions