From 9c59554f16bb67f6576faa800fe309f99a1d9206 Mon Sep 17 00:00:00 2001 From: Gabriel Cousin <7649529+GabrielCousin@users.noreply.github.com> Date: Mon, 27 Sep 2021 21:43:47 +0200 Subject: [PATCH] Test helper | Add type property in mocked DataTransfer --- addon-test-support/helpers/mock-event.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/addon-test-support/helpers/mock-event.js b/addon-test-support/helpers/mock-event.js index c1f2ed2..b29e328 100644 --- a/addon-test-support/helpers/mock-event.js +++ b/addon-test-support/helpers/mock-event.js @@ -1,26 +1,32 @@ class DataTransfer { constructor() { this.data = {}; + this.types = []; } setData(type, value) { + const _type = type === 'Text' ? 'text/plain' : type; + + if (!this.types.includes(_type)) { + this.types.push(_type); + } + this.data[type] = value; return this; } - getData(type = "Text") { + getData(type = 'Text') { return this.data[type]; } - setDragImage() { - } + setDragImage() {} } export default class MockEvent { constructor(options = {}) { this.dataTransfer = new DataTransfer(); this.dataTransfer.setData('Text', options.dataTransferData); - this.setProperties(options) + this.setProperties(options); } useDataTransferData(otherEvent) { @@ -35,15 +41,13 @@ export default class MockEvent { return this; } - preventDefault() { - } + preventDefault() {} - stopPropagation() { - } + stopPropagation() {} } export function createDomEvent(type) { - let event = document.createEvent("CustomEvent"); + let event = document.createEvent('CustomEvent'); event.initCustomEvent(type, true, true, null); event.dataTransfer = new DataTransfer(); return event;