feat(store): initial release (#279)

This commit is contained in:
rahim
2026-01-02 14:41:58 +11:00
committed by GitHub
parent c9a216dd2d
commit d74e4e6701
54 changed files with 6047 additions and 66 deletions
+77
View File
@@ -0,0 +1,77 @@
import { describe, expect, it } from 'vitest';
import { isEventLike } from './event-like';
describe('event-like', () => {
describe('isEventLike', () => {
it('returns true for objects with type and timeStamp', () => {
expect(isEventLike({ type: 'click', timeStamp: 123 })).toBe(true);
expect(isEventLike({ type: 'play', timeStamp: 0 })).toBe(true);
expect(isEventLike({ type: '', timeStamp: Date.now() })).toBe(true);
});
it('returns true for objects with additional properties', () => {
expect(
isEventLike({
type: 'click',
timeStamp: 123,
isTrusted: true,
target: null,
}),
).toBe(true);
});
it('returns true for DOM Events', () => {
const event = new Event('click');
expect(isEventLike(event)).toBe(true);
});
it('returns true for CustomEvent', () => {
const event = new CustomEvent('custom', { detail: { foo: 'bar' } });
expect(isEventLike(event)).toBe(true);
});
it('returns false for missing type', () => {
expect(isEventLike({ timeStamp: 123 })).toBe(false);
});
it('returns false for missing timeStamp', () => {
expect(isEventLike({ type: 'click' })).toBe(false);
});
it('returns false for non-string type', () => {
expect(isEventLike({ type: 123, timeStamp: 123 })).toBe(false);
expect(isEventLike({ type: null, timeStamp: 123 })).toBe(false);
expect(isEventLike({ type: undefined, timeStamp: 123 })).toBe(false);
});
it('returns false for non-number timeStamp', () => {
expect(isEventLike({ type: 'click', timeStamp: '123' })).toBe(false);
expect(isEventLike({ type: 'click', timeStamp: null })).toBe(false);
expect(isEventLike({ type: 'click', timeStamp: undefined })).toBe(false);
});
it('returns false for null', () => {
expect(isEventLike(null)).toBe(false);
});
it('returns false for undefined', () => {
expect(isEventLike(undefined)).toBe(false);
});
it('returns false for primitives', () => {
expect(isEventLike('event')).toBe(false);
expect(isEventLike(123)).toBe(false);
expect(isEventLike(true)).toBe(false);
});
it('returns false for arrays', () => {
expect(isEventLike([])).toBe(false);
expect(isEventLike(['click', 123])).toBe(false);
});
it('returns false for functions', () => {
expect(isEventLike(() => {})).toBe(false);
});
});
});