-
Notifications
You must be signed in to change notification settings - Fork 325
/
Copy pathignoreEventValue.test.ts
50 lines (45 loc) · 1.52 KB
/
ignoreEventValue.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { noop } from '@clerk/shared/testUtils';
import { ignoreEventValue } from '../ignoreEventValue';
describe('ignoreNonEventValue', () => {
it('allows non event values', () => {
expect(ignoreEventValue(true)).toEqual(true);
expect(ignoreEventValue({ name: 'test' })).toEqual({ name: 'test' });
expect(ignoreEventValue(undefined)).toEqual(undefined);
expect(ignoreEventValue(null)).toEqual(null);
expect(ignoreEventValue(null)).toEqual(null);
expect(ignoreEventValue(0)).toEqual(0);
expect(ignoreEventValue(10)).toEqual(10);
expect(ignoreEventValue('')).toEqual('');
});
it('ignores event values', () => {
expect(ignoreEventValue(new Event('click'))).toEqual(undefined);
expect(
ignoreEventValue({
target: '',
currentTarget: '',
preventDefault: noop,
}),
).toEqual(undefined);
});
it('ignores synthetic event values (react)', () => {
expect(
ignoreEventValue({
get target() {
return null;
},
get currentTarget() {
return null;
},
get preventDefault() {
return null;
},
}),
).toEqual(undefined);
});
it('only allows values of specified types', () => {
expect(ignoreEventValue(noop)).toEqual(noop);
expect(ignoreEventValue(noop, { requireType: 'function' })).toEqual(noop);
expect(ignoreEventValue(true, { requireType: 'function' })).toEqual(undefined);
expect(ignoreEventValue(true, { requireType: 'boolean' })).toEqual(true);
});
});