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

[Test given] Issue with order of execution with async event listener #1684

Open
Spixmaster opened this issue Jan 11, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Spixmaster
Copy link

Spixmaster commented Jan 11, 2025

happy-dom v16.5.3

Example:

import {assert} from "assert-ts";
import {expect, test} from "bun:test";
import {Window} from "happy-dom";

test("showcase", (): undefined =>
{
    const window: Window = new Window();
    //@ts-expect-error
    global.window = window;
    //@ts-expect-error
    global.document = window.document;
    localStorage.clear();
    document.body.innerHTML = `<div id="a"></div>`;

    const a: HTMLElement | null = document.getElementById("a");
    assert(a !== null);

    a.addEventListener("click", async (): Promise<undefined> =>
    {
        console.log("test 2");

        const response: Response = await fetch("https://google.com");
        assert(response.status === 200);

        console.log("test 3");
    });

    console.log("test 1");

    //@ts-expect-error
    a.dispatchEvent(new window.Event("click"));
    console.log("test 4");
});

Expeced result:

I want it to print:

test 1
test 2
test 3
test 4

Actual result:

❯ bun test --coverage tests/src-web/typescript/payment.test.ts
bun test v1.1.42 (50eec002)

test 1
test 2
test 4
✓ showcase [2.83ms]
test 3
@Spixmaster Spixmaster added the bug Something isn't working label Jan 11, 2025
@Spixmaster Spixmaster changed the title Issue with order of execution with async event listener [Test given] Issue with order of execution with async event listener Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant