From 55f3820cf9cb7e6fb805a6d3be4661aebeab809d Mon Sep 17 00:00:00 2001 From: Adam Obuchowicz Date: Fri, 1 Mar 2024 16:51:33 +0100 Subject: [PATCH] Fix selection tests (#9240) 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. --- app/gui2/src/composables/__tests__/selection.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/gui2/src/composables/__tests__/selection.test.ts b/app/gui2/src/composables/__tests__/selection.test.ts index 08826d78caf2..b5c4aee5dd71 100644 --- a/app/gui2/src/composables/__tests__/selection.test.ts +++ b/app/gui2/src/composables/__tests__/selection.test.ts @@ -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' @@ -23,7 +23,7 @@ function selectionWithMockData(sceneMousePos?: Ref) { // 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]} @@ -54,7 +54,7 @@ const areas: Record = { // 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]} @@ -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 } }