Skip to content

Commit 69f5c1d

Browse files
committed
test: update existing tests for improved accuracy
- Remove afterEach cleanup logic (unnecessary with Vitest browser mode auto-reset) - Remove redundant test cases and improve test names in blokr.test.ts - Change event-blocking.test.ts from mousedown to click event tests - Reflect core improvements from previous commits
1 parent de8827a commit 69f5c1d

2 files changed

Lines changed: 9 additions & 36 deletions

File tree

tests/blokr.test.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { describe, it, expect, afterEach, vi } from 'vitest';
1+
import { describe, it, expect, vi } from 'vitest';
22
import blokr from '../src/blokr.ts';
33

44
describe('Blokr Factory Function', () => {
5-
afterEach(() => {
6-
// Clean up any locks after each test
7-
const globalInstance = blokr();
8-
if (globalInstance.isLocked()) {
9-
globalInstance.unlock();
10-
}
11-
});
12-
135
describe('Factory Behavior', () => {
146
it('should return a Blokr instance', () => {
157
const instance = blokr();
@@ -196,18 +188,6 @@ describe('Blokr Factory Function', () => {
196188
vi.useRealTimers();
197189
});
198190

199-
it('should not set timeout when timeout is 0', () => {
200-
const instance = blokr();
201-
const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout');
202-
203-
instance.lock({ timeout: 0 });
204-
205-
expect(setTimeoutSpy).not.toHaveBeenCalled();
206-
207-
setTimeoutSpy.mockRestore();
208-
instance.unlock();
209-
});
210-
211191
it('should clear timeout on manual unlock', () => {
212192
vi.useFakeTimers();
213193

@@ -282,11 +262,12 @@ describe('Blokr Factory Function', () => {
282262
instance.unlock();
283263
});
284264

285-
it('should use default scope "inside" for global instance', () => {
265+
it('should block all events for global instance regardless of scope', () => {
286266
const instance = blokr();
287-
// Global instance with no target should still work (no filtering)
288-
const result = instance.lock();
267+
// Global instance blocks all events, scope parameter is ignored
268+
const result = instance.lock({ scope: 'outside' });
289269
expect(result).toBe(true);
270+
expect(instance.isLocked()).toBe(true);
290271
instance.unlock();
291272
});
292273
});

tests/event-blocking.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
import { describe, it, expect, afterEach, vi } from 'vitest';
1+
import { describe, it, expect, vi } from 'vitest';
22
import blokr from '../src/blokr.ts';
33

44
describe('Event Blocking Integration', () => {
5-
afterEach(() => {
6-
// Clean up any locks after each test
7-
const globalInstance = blokr();
8-
if (globalInstance.isLocked()) {
9-
globalInstance.unlock();
10-
}
11-
});
12-
135
describe('Global Event Blocking', () => {
14-
it('should block mousedown events when locked globally', () => {
6+
it('should block click events when locked globally', () => {
157
const handler = vi.fn();
168
const element = document.createElement('button');
17-
element.addEventListener('mousedown', handler);
9+
element.addEventListener('click', handler);
1810
document.body.appendChild(element);
1911

2012
const instance = blokr();
2113
instance.lock();
2214

23-
const event = new MouseEvent('mousedown', {
15+
const event = new MouseEvent('click', {
2416
bubbles: true,
2517
cancelable: true
2618
});

0 commit comments

Comments
 (0)