Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Update eventData.test.ts
  • Loading branch information
ShaMan123 committed Sep 13, 2023
1 parent d64f256 commit 2a95437
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/canvas/__tests__/eventData.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable no-restricted-globals */
import '../../../jest.extend';
import type { TPointerEvent } from '../../EventTypeDefs';
import { Point } from '../../Point';
import { Group } from '../../shapes/Group';
import { IText } from '../../shapes/IText/IText';
import { FabricObject } from '../../shapes/Object/FabricObject';
import type { TMat2D } from '../../typedefs';
import { Canvas } from '../Canvas';

Expand Down Expand Up @@ -100,3 +103,22 @@ describe('Canvas event data', () => {
}
);
});

it('A selected subtarget should not fire an event twice', () => {
const target = new FabricObject();
const group = new Group([target], {
subTargetCheck: true,
interactive: true,
});
const canvas = new Canvas(null);
canvas.add(group);
const targetSpy = jest.fn();
target.on('mousedown', targetSpy);
jest.spyOn(canvas, '_checkTarget').mockReturnValue(true);
canvas.__onMouseDown({
target: canvas.getSelectionElement(),
clientX: 0,
clientY: 0,
} as unknown as TPointerEvent);
expect(targetSpy).toHaveBeenCalledTimes(1);
});

0 comments on commit 2a95437

Please sign in to comment.