Skip to content

Commit

Permalink
Fix selection tests (#9240)
Browse files Browse the repository at this point in the history
Sometimes our test realizes, that `currentTarget` of `MouseEvent` is a read-only property. I have no idea why it does not do it every time, but this fix should work.
  • Loading branch information
farmaazon authored Mar 1, 2024
1 parent 4316709 commit 55f3820
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/gui2/src/composables/__tests__/selection.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Rect } from '@/util/data/rect'
import { Vec2 } from '@/util/data/vec2'
import { expect, test } from 'vitest'
import { expect, test, vi } from 'vitest'
import { proxyRefs, ref, type Ref } from 'vue'
import { useSelection } from '../selection'

Expand All @@ -23,7 +23,7 @@ function selectionWithMockData(sceneMousePos?: Ref<Vec2>) {

// TODO[ao]: Skipping test, as they often fail in CI
// (for example https://github.com/enso-org/enso/actions/runs/8102076908/job/22163122663)
test.skip.each`
test.each`
click | modifiers | expected
${1} | ${[]} | ${[1]}
${3} | ${[]} | ${[3]}
Expand Down Expand Up @@ -54,7 +54,7 @@ const areas: Record<string, Rect> = {

// TODO[ao]: Skipping test, as they often fail in CI
// (for example https://github.com/enso-org/enso/actions/runs/8102076908/job/22163122663)
test.skip.each`
test.each`
areaId | modifiers | expected
${'left'} | ${[]} | ${[1, 3]}
${'right'} | ${[]} | ${[2, 4]}
Expand Down Expand Up @@ -103,12 +103,12 @@ test.skip.each`
dragCase(new Vec2(area.right, area.top), new Vec2(area.left, area.bottom))
})

// There is no PointerEvent class in jsdom (yet).
class MockPointerEvent extends MouseEvent {
currentTarget: EventTarget | null
pointerId: number
readonly pointerId: number
constructor(type: string, options: MouseEventInit & { currentTarget?: Element | undefined }) {
super(type, options)
this.currentTarget = options.currentTarget ?? null
vi.spyOn(this, 'currentTarget', 'get').mockReturnValue(options.currentTarget ?? null)
this.pointerId = 4
}
}
Expand Down

0 comments on commit 55f3820

Please sign in to comment.