Skip to content

Commit d2c2975

Browse files
committed
Add tests for selectors
1 parent 530c390 commit d2c2975

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/tiny-events.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ describe('on, off, and trigger methods', () => {
2121
const $ = tinyEvents('#btn-does-not-exist').on('click', () => {});
2222
expect($).toBeInstanceOf(TinyEvents);
2323
});
24+
test('should be able to attach event to multiple elements', () => {
25+
document.body.innerHTML = `<button class="btn">Button 1</button>
26+
<button id="btn-2">Button 2</button>`;
27+
28+
let times = 0;
29+
tinyEvents('.btn, #btn-2').on('click', () => {
30+
times++;
31+
});
32+
userEvent.click(screen.getByText('Button 1'));
33+
userEvent.click(screen.getByText('Button 2'));
34+
35+
expect(times).toBe(2);
36+
});
2437
test('should be able to attach event listeners that works only once', () => {
2538
document.body.innerHTML = `<button class="btn">Button 2</button>
2639
<button class="btn">Button 3</button>`;

0 commit comments

Comments
 (0)