From b873d7b81e06e1f8276adb00d8776db19019d16f Mon Sep 17 00:00:00 2001 From: David Ortner Date: Sun, 7 Apr 2024 14:13:00 +0200 Subject: [PATCH] chore: [#1390] Adds Bun integration test for adding an event listener --- .../global-registrator/test/bun/Bun.test.js | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/global-registrator/test/bun/Bun.test.js b/packages/global-registrator/test/bun/Bun.test.js index fc3b2e88b..3d1225ea0 100644 --- a/packages/global-registrator/test/bun/Bun.test.js +++ b/packages/global-registrator/test/bun/Bun.test.js @@ -47,7 +47,20 @@ test('CSS', () => { } `; - expect(globalThis.getComputedStyle(document.body).backgroundColor).toBe('green'); + expect(getComputedStyle(document.body).backgroundColor).toBe('green'); +}); + +test('Add event listener', () => { + const div = document.createElement('div'); + document.body.appendChild(div); + + document.body.addEventListener('click', () => { + div.style.backgroundColor = 'green'; + }); + + div.dispatchEvent(new Event('click', { bubbles: true })); + + expect(getComputedStyle(div).backgroundColor).toBe('green'); }); test('Window getters', () => { @@ -64,8 +77,8 @@ test('Window getters', () => { }); test('Window location', () => { - globalThis.location.href = 'https://example.com/'; - expect(globalThis.location.href).toBe('https://example.com/'); + location.href = 'https://example.com/'; + expect(location.href).toBe('https://example.com/'); }); test('Window options', () => { @@ -82,8 +95,8 @@ test('Window options', () => { } }); - expect(globalThis.location.href).toBe('https://example.com/'); - expect(globalThis.innerWidth).toBe(1920); - expect(globalThis.innerHeight).toBe(1080); - expect(globalThis.navigator.userAgent).toBe('Custom User Agent'); + expect(location.href).toBe('https://example.com/'); + expect(innerWidth).toBe(1920); + expect(innerHeight).toBe(1080); + expect(navigator.userAgent).toBe('Custom User Agent'); });