Skip to content

Commit 41bec35

Browse files
authored
Merge branch 'master' into pr/add-package-lock
2 parents 9b20d95 + b9900f8 commit 41bec35

File tree

4 files changed

+76
-26
lines changed

4 files changed

+76
-26
lines changed

.all-contributorsrc

+10
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,16 @@
10151015
"profile": "https://nickmccurdy.com/",
10161016
"contributions": [
10171017
"doc",
1018+
"code",
1019+
"test"
1020+
]
1021+
},
1022+
{
1023+
"login": "calebmer",
1024+
"name": "Caleb Meredith",
1025+
"avatar_url": "https://avatars1.githubusercontent.com/u/8282507?v=4",
1026+
"profile": "http://calebmer.com",
1027+
"contributions": [
10181028
"code"
10191029
]
10201030
}

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ Thanks goes to these people ([emoji key][emojis]):
262262
<td align="center"><a href="https://github.com/benmonro"><img src="https://avatars3.githubusercontent.com/u/399236?v=4" width="100px;" alt=""/><br /><sub><b>Ben Monro</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=benmonro" title="Code">💻</a> <a href="#ideas-benmonro" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=benmonro" title="Tests">⚠️</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=benmonro" title="Documentation">📖</a></td>
263263
<td align="center"><a href="https://github.com/smeijer"><img src="https://avatars1.githubusercontent.com/u/1196524?v=4" width="100px;" alt=""/><br /><sub><b>Stephan Meijer</b></sub></a><br /><a href="#ideas-smeijer" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=smeijer" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=smeijer" title="Tests">⚠️</a></td>
264264
<td align="center"><a href="https://joaoforja.com/"><img src="https://avatars2.githubusercontent.com/u/7002157?v=4" width="100px;" alt=""/><br /><sub><b>João Forja</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=Jnforja" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=Jnforja" title="Tests">⚠️</a></td>
265-
<td align="center"><a href="https://nickmccurdy.com/"><img src="https://avatars0.githubusercontent.com/u/927220?v=4" width="100px;" alt=""/><br /><sub><b>Nick McCurdy</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=nickmccurdy" title="Documentation">📖</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=nickmccurdy" title="Code">💻</a></td>
265+
<td align="center"><a href="https://nickmccurdy.com/"><img src="https://avatars0.githubusercontent.com/u/927220?v=4" width="100px;" alt=""/><br /><sub><b>Nick McCurdy</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=nickmccurdy" title="Documentation">📖</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=nickmccurdy" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=nickmccurdy" title="Tests">⚠️</a></td>
266+
<td align="center"><a href="http://calebmer.com"><img src="https://avatars1.githubusercontent.com/u/8282507?v=4" width="100px;" alt=""/><br /><sub><b>Caleb Meredith</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=calebmer" title="Code">💻</a></td>
266267
</tr>
267268
</table>
268269

src/__tests__/events.js

+46-11
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,21 @@ const eventTypes = [
140140

141141
const allEvents = Object.keys(eventMap)
142142

143-
const bubblingEvents = allEvents
144-
.filter(eventName => eventMap[eventName].defaultInit.bubbles)
143+
const bubblingEvents = allEvents.filter(
144+
eventName => eventMap[eventName].defaultInit.bubbles,
145+
)
145146

146-
const composedEvents = allEvents
147-
.filter(eventName => eventMap[eventName].defaultInit.composed)
147+
const composedEvents = allEvents.filter(
148+
eventName => eventMap[eventName].defaultInit.composed,
149+
)
148150

149-
const nonBubblingEvents = allEvents
150-
.filter(eventName => !bubblingEvents.includes(eventName))
151+
const nonBubblingEvents = allEvents.filter(
152+
eventName => !bubblingEvents.includes(eventName),
153+
)
151154

152-
const nonComposedEvents = allEvents
153-
.filter(eventName => !composedEvents.includes(eventName))
155+
const nonComposedEvents = allEvents.filter(
156+
eventName => !composedEvents.includes(eventName),
157+
)
154158

155159
eventTypes.forEach(({type, events, elementType}) => {
156160
describe(`${type} Events`, () => {
@@ -203,7 +207,7 @@ describe(`Composed Events`, () => {
203207
const spy = jest.fn()
204208
node.addEventListener(event.toLowerCase(), spy)
205209

206-
const shadowRoot = node.attachShadow({ mode: 'closed' })
210+
const shadowRoot = node.attachShadow({mode: 'closed'})
207211
const innerNode = document.createElement('div')
208212
shadowRoot.appendChild(innerNode)
209213

@@ -218,7 +222,7 @@ describe(`Composed Events`, () => {
218222
const spy = jest.fn()
219223
node.addEventListener(event.toLowerCase(), spy)
220224

221-
const shadowRoot = node.attachShadow({ mode: 'closed' })
225+
const shadowRoot = node.attachShadow({mode: 'closed'})
222226
const innerNode = document.createElement('div')
223227
shadowRoot.appendChild(innerNode)
224228

@@ -234,7 +238,7 @@ describe(`Aliased Events`, () => {
234238
const node = document.createElement('div')
235239
const spy = jest.fn()
236240
node.addEventListener(eventAliasMap[eventAlias].toLowerCase(), spy)
237-
241+
238242
fireEvent[eventAlias](node)
239243
expect(spy).toHaveBeenCalledTimes(1)
240244
})
@@ -303,6 +307,37 @@ test('assigning the files property on dataTransfer', () => {
303307
expect(spy.mock.calls[0][0]).toHaveProperty('dataTransfer.files', [file])
304308
})
305309

310+
test('assigns clipboardData properties', () => {
311+
const node = document.createElement('div')
312+
const spy = jest.fn()
313+
node.addEventListener('paste', spy)
314+
const clipboardData = {
315+
dropEffect: 'none',
316+
effectAllowed: 'uninitialized',
317+
files: [],
318+
items: [
319+
{
320+
kind: 'string',
321+
type: 'text/plain',
322+
file: {
323+
getAsFile() {
324+
return null
325+
},
326+
},
327+
},
328+
],
329+
types: ['text/plain'],
330+
getData() {
331+
return 'example'
332+
},
333+
}
334+
fireEvent.paste(node, {clipboardData})
335+
expect(spy).toHaveBeenCalledTimes(1)
336+
expect(spy.mock.calls[0][0].clipboardData).toBe(clipboardData)
337+
expect(clipboardData.items[0].file.getAsFile()).toBeNull()
338+
expect(clipboardData.getData('text')).toBe('example')
339+
})
340+
306341
test('fires events on Window', () => {
307342
const messageSpy = jest.fn()
308343
window.addEventListener('message', messageSpy)

src/events.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,25 @@ Object.keys(eventMap).forEach(key => {
6262
event[eventKey] = otherInit[eventKey]
6363
})
6464
}
65-
66-
const {dataTransfer} = eventInit
67-
if (typeof dataTransfer === 'object') {
68-
// DataTransfer is not supported in jsdom: https://github.com/jsdom/jsdom/issues/1568
69-
/* istanbul ignore if */
70-
if (typeof window.DataTransfer === 'function') {
71-
Object.defineProperty(event, 'dataTransfer', {
72-
value: Object.assign(new window.DataTransfer(), dataTransfer),
73-
})
74-
} else {
75-
Object.defineProperty(event, 'dataTransfer', {
76-
value: dataTransfer,
77-
})
65+
66+
// DataTransfer is not supported in jsdom: https://github.com/jsdom/jsdom/issues/1568
67+
['dataTransfer', 'clipboardData'].forEach(dataTransferKey => {
68+
const dataTransferValue = eventInit[dataTransferKey];
69+
70+
if (typeof dataTransferValue === 'object') {
71+
/* istanbul ignore if */
72+
if (typeof window.DataTransfer === 'function') {
73+
Object.defineProperty(event, dataTransferKey, {
74+
value: Object.assign(new window.DataTransfer(), dataTransferValue)
75+
})
76+
} else {
77+
Object.defineProperty(event, dataTransferKey, {
78+
value: dataTransferValue
79+
})
80+
}
7881
}
79-
}
82+
})
83+
8084
return event
8185
}
8286

0 commit comments

Comments
 (0)