-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathenumerate-entries.test.ts
More file actions
43 lines (37 loc) · 1.63 KB
/
enumerate-entries.test.ts
File metadata and controls
43 lines (37 loc) · 1.63 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
36
37
38
39
40
41
42
43
import { enumerate, enumerateContents } from '../src/helper/enumerate-entries';
describe('enumerate', () => {
it('should not throw when entries is empty array', () => {
const process = jest.fn();
expect(() => enumerate([], process)).not.toThrow();
expect(process).not.toHaveBeenCalled();
});
it('should call process for each entry', () => {
const entries = [{ uid: '1' }, { uid: '2' }];
const process = jest.fn();
enumerate(entries, process);
expect(process).toHaveBeenCalledTimes(2);
expect(process).toHaveBeenNthCalledWith(1, { uid: '1' });
expect(process).toHaveBeenNthCalledWith(2, { uid: '2' });
});
});
describe('enumerateContents', () => {
it('should return content as string when content is not array and type is not doc', () => {
const content = { type: 'paragraph', children: [] } as any;
const result = enumerateContents(content);
expect(result).toEqual(content);
});
it('should return array of strings when content is array of docs', () => {
const doc: any = { type: 'doc', children: [] };
const result = enumerateContents([doc, doc]);
expect(Array.isArray(result)).toBe(true);
expect((result as string[]).length).toBe(2);
expect((result as string[])[0]).toBe('');
expect((result as string[])[1]).toBe('');
});
it('should throw when content is null', () => {
expect(() => enumerateContents(null as any)).toThrow();
});
it('should throw when content is undefined', () => {
expect(() => enumerateContents(undefined as any)).toThrow();
});
});