test(actions): add defaultPrevented coverage for clickOutside (#195)

The action already checks event.defaultPrevented before dispatching
clickoutside, but that branch had no test. Add the missing case and
add a one-line comment explaining why capture phase is used.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-15 12:46:04 +02:00
parent 731cdc75ab
commit 4446e80875
2 changed files with 13 additions and 0 deletions

View File

@@ -51,6 +51,18 @@ describe('clickOutside action', () => {
expect(fired).toBe(false);
});
it('does not dispatch clickoutside when event.defaultPrevented is true', () => {
const node = makeNode();
const outside = makeNode();
let fired = false;
node.addEventListener('clickoutside', () => (fired = true));
clickOutside(node);
const event = new MouseEvent('click', { bubbles: true, cancelable: true });
event.preventDefault();
outside.dispatchEvent(event);
expect(fired).toBe(false);
});
it('removes the listener on destroy', () => {
const node = makeNode();
const outside = makeNode();

View File

@@ -5,6 +5,7 @@ export function clickOutside(node: HTMLElement): { destroy: () => void } {
}
}
// Capture phase (true) ensures this fires before any child stopPropagation() calls.
document.addEventListener('click', handleClick, true);
return {