capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.14k stars 189 forks source link

Jest environment could detect some errors it is currently silencing #1345

Open yjaaidi opened 4 months ago

yjaaidi commented 4 months ago

The following tests will not show any error when using happy-dom environment:

test('leak microtask', () => {
  queueMicrotask(() => expect(1).toBe(2));
});

test('leak timer', () => {
  setTimeout(() => expect(1).toBe(2), 1000);
});

It would be nice if the environment could detect pending timers or flush (until timeout) when torn down. This could be achieved with something like await this.global.happyDOM.waitUntilComplete() in the teardown.

I'll be happy to help with a PR.

Cf. https://github.com/jestjs/jest/issues/14984