Skip to content

Commit

Permalink
frontend: mock ClipboardEvent and DragEvent class constructors for te…
Browse files Browse the repository at this point in the history
…sts with TipTap

This is necessary because of ueberdosis/tiptap#4354.
  • Loading branch information
BacLuc committed Nov 7, 2023
1 parent 32a6db5 commit 8c8b62f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import { ApiMock } from '@/components/form/api/__tests__/ApiMock'
import { i18n } from '@/plugins'
import { mount as mountComponent } from '@vue/test-utils'
import { waitForDebounce } from '@/test/util'
import { mockEventClass } from '@/../tests/mockEventClass'

Vue.use(Vuetify)
Vue.use(formBaseComponents)

mockEventClass('ClipboardEvent')
mockEventClass('DragEvent')

describe('An ApiTextarea', () => {
let vuetify
let wrapper
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/form/base/__tests__/ETextArea.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import formBaseComponents from '@/plugins/formBaseComponents'

import { mount as mountComponent } from '@vue/test-utils'
import ETextarea from '../ETextarea.vue'
import { mockEventClass } from '@/../tests/mockEventClass'

Vue.use(Vuetify)
Vue.use(formBaseComponents)

mockEventClass('ClipboardEvent')
mockEventClass('DragEvent')

describe('An ETextArea', () => {
let vuetify

Expand Down
26 changes: 26 additions & 0 deletions frontend/tests/mockEventClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @param { "ClipboardEvent" | "DragEvent" } eventName
*/
export function mockEventClass(eventName) {
const eventBackup = window[eventName]
const eventClass = class extends Event {
constructor(type, eventInitDict) {
// noinspection JSCheckFunctionSignatures
super(type, eventInitDict)
}
}

beforeEach(() => {
if (!eventBackup) {
window[eventName] = eventClass
} else {
console.error(
`you don't need to mock ${eventName} anymore, the test runner supports it now natively`
)
}
})

afterEach(() => {
window[eventName] = eventBackup
})
}

0 comments on commit 8c8b62f

Please sign in to comment.