-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
one-event.test.ts
32 lines (27 loc) · 1008 Bytes
/
one-event.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {test, expect} from 'vitest';
import {anchor} from './vitest.setup.js';
import oneEvent from './one-event.js';
test('should resolve after one event', async t => {
const promise = oneEvent('a', 'click');
anchor.click();
const event = await promise;
expect(event).toBeInstanceOf(MouseEvent);
});
test('should resolve with `undefined` after it’s aborted', async t => {
const controller = new AbortController();
const promise = oneEvent('a', 'click', {signal: controller.signal});
controller.abort();
const event = await promise;
expect(event).toBeUndefined();
});
test('should resolve with `undefined` if the signal has already aborted', async t => {
const promise = oneEvent('a', 'click', {signal: AbortSignal.abort()});
const event = await promise;
expect(event).toBeUndefined();
});
test('should accept an array of selectors', async t => {
const promise = oneEvent(['a', 'b'], 'click');
anchor.click();
const event = await promise;
expect(event).toBeInstanceOf(MouseEvent);
});