-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathutils.spec.ts
35 lines (30 loc) · 921 Bytes
/
utils.spec.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
/**
* @jest-environment jsdom
*/
import { W } from '../src/constants';
import { convertToKB, pushTask } from '../src/utils';
describe('utils', () => {
let spy: jest.SpyInstance;
describe('.convertToKB()', () => {
it('should convert number to Kilo Bytes', () => {
expect(convertToKB(100000000)).toEqual(95.3674);
});
it('should return null when input is not a number', () => {
// @ts-ignore
expect(convertToKB('100000000')).toEqual(null);
});
});
describe('.pushTask()', () => {
it('should call cb() if requestIdleCallback is undefined', () => {
spy = jest.fn();
pushTask(spy);
expect(spy.mock.calls.length).toEqual(1);
});
it('should call requestIdleCallback if is defined', () => {
spy = jest.fn();
(W as any).requestIdleCallback = spy;
pushTask(() => {});
expect(spy.mock.calls.length).toEqual(1);
});
});
});