From 4421397b1706c20e333c6afcee4f9fb00e075582 Mon Sep 17 00:00:00 2001 From: Vince Malone Date: Tue, 29 Dec 2020 16:40:39 -0500 Subject: [PATCH] feat: support TransitionEvent init properties --- src/__tests__/events.js | 16 ++++++++++++++++ src/events.js | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/__tests__/events.js b/src/__tests__/events.js index 5fc9d7fd4..40c8bb4ed 100644 --- a/src/__tests__/events.js +++ b/src/__tests__/events.js @@ -358,6 +358,22 @@ test('assigns clipboardData properties', () => { expect(clipboardData.getData('text')).toBe('example') }) +test('assigns TransitionEvent init properties', () => { + const node = document.createElement('div') + const spy = jest.fn() + node.addEventListener('transitionend', spy) + const transitionEventInit = { + propertyName: 'opacity', + elapsedTime: 100, + pseudoElement: '', + } + fireEvent.transitionEnd(node, transitionEventInit) + expect(spy).toHaveBeenCalledTimes(1) + expect(spy.mock.calls[0][0]).toEqual( + expect.objectContaining(transitionEventInit), + ) +}) + test('fires events on Window', () => { const messageSpy = jest.fn() window.addEventListener('message', messageSpy) diff --git a/src/events.js b/src/events.js index 57446bf8d..efb6c99f5 100644 --- a/src/events.js +++ b/src/events.js @@ -62,6 +62,20 @@ function createEvent( }) } + // TransitionEvent is not supported in jsdom: https://github.com/jsdom/jsdom/issues/1781 + if (EventType === 'TransitionEvent') { + const transitionEventProperties = [ + 'propertyName', + 'elapsedTime', + 'pseudoElement', + ] + transitionEventProperties.forEach(property => { + Object.defineProperty(event, property, { + value: eventInit[property], + }) + }) + } + // DataTransfer is not supported in jsdom: https://github.com/jsdom/jsdom/issues/1568 const dataTransferProperties = ['dataTransfer', 'clipboardData'] dataTransferProperties.forEach(dataTransferKey => {