Skip to content

Commit b0a0343

Browse files
author
Vince Malone
committed
feat: support TransitionEvent init properties
1 parent ec1b642 commit b0a0343

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/__tests__/events.js

+16
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,22 @@ test('assigns clipboardData properties', () => {
358358
expect(clipboardData.getData('text')).toBe('example')
359359
})
360360

361+
test('assigns TransitionEvent init properties', () => {
362+
const node = document.createElement('div')
363+
const spy = jest.fn()
364+
node.addEventListener('transitionend', spy)
365+
const transitionEventInit = {
366+
propertyName: 'opacity',
367+
elapsedTime: 100,
368+
pseudoElement: '',
369+
}
370+
fireEvent.transitionEnd(node, transitionEventInit)
371+
expect(spy).toHaveBeenCalledTimes(1)
372+
expect(spy.mock.calls[0][0]).toEqual(
373+
expect.objectContaining(transitionEventInit),
374+
)
375+
})
376+
361377
test('fires events on Window', () => {
362378
const messageSpy = jest.fn()
363379
window.addEventListener('message', messageSpy)

src/events.js

+17
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ function createEvent(
6262
})
6363
}
6464

65+
// TransitionEvent is not supported in jsdom: https://github.com/jsdom/jsdom/issues/1781
66+
if (
67+
EventType === 'TransitionEvent' &&
68+
typeof window.TransitionEvent !== 'function'
69+
) {
70+
const transitionEventProperties = [
71+
'propertyName',
72+
'elapsedTime',
73+
'pseudoElement',
74+
]
75+
transitionEventProperties.forEach(property => {
76+
Object.defineProperty(event, property, {
77+
value: eventInit[property],
78+
})
79+
})
80+
}
81+
6582
// DataTransfer is not supported in jsdom: https://github.com/jsdom/jsdom/issues/1568
6683
const dataTransferProperties = ['dataTransfer', 'clipboardData']
6784
dataTransferProperties.forEach(dataTransferKey => {

0 commit comments

Comments
 (0)