-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathbase.test.ts
More file actions
35 lines (29 loc) · 1.19 KB
/
base.test.ts
File metadata and controls
35 lines (29 loc) · 1.19 KB
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
33
34
35
import { baseSyntheticEvent } from '../base';
test('returns object with all required properties and default values', () => {
const event = baseSyntheticEvent();
expect(event.currentTarget).toEqual({});
expect(event.target).toEqual({});
expect(event.timeStamp).toBe(0);
expect(event.isDefaultPrevented?.()).toBe(false);
expect(event.isPropagationStopped?.()).toBe(false);
expect(event.isPersistent?.()).toBe(false);
expect(typeof event.stopPropagation).toBe('function');
expect(typeof event.preventDefault).toBe('function');
expect(typeof event.persist).toBe('function');
});
test('returns a new object instance on each call', () => {
const event1 = baseSyntheticEvent();
const event2 = baseSyntheticEvent();
expect(event1).not.toBe(event2);
expect(event1.currentTarget).not.toBe(event2.currentTarget);
expect(event1.target).not.toBe(event2.target);
});
test('can be spread into other objects', () => {
const extendedEvent = {
...baseSyntheticEvent(),
nativeEvent: { test: 'value' },
};
expect(extendedEvent).toHaveProperty('currentTarget');
expect(extendedEvent).toHaveProperty('preventDefault');
expect(extendedEvent.nativeEvent).toEqual({ test: 'value' });
});