forked from aws-samples/amazon-q-slack-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.test.ts
24 lines (22 loc) · 919 Bytes
/
utils.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
import { describe, test, expect } from '@jest/globals';
import * as Utils from '@src/utils';
describe('Test global utilities', () => {
test('Test is empty', () => {
expect(Utils.isEmpty(0)).toBeFalsy();
expect(Utils.isEmpty(false)).toBeFalsy();
expect(Utils.isEmpty(undefined)).toBeTruthy();
expect(Utils.isEmpty(new Date())).toBeFalsy();
expect(Utils.isEmpty({})).toBeTruthy();
expect(Utils.isEmpty([])).toBeTruthy();
expect(Utils.isEmpty({ a: [] })).toBeFalsy();
expect(Utils.isEmpty(['a'])).toBeFalsy();
expect(Utils.isEmpty('')).toBeTruthy();
expect(Utils.isEmpty([{}, {}])).toBeTruthy();
expect(Utils.isEmpty([[]])).toBeTruthy();
});
test('get or throw if empty', () => {
expect(() => Utils.getOrThrowIfEmpty('')).toThrow();
expect(() => Utils.getOrThrowIfEmpty(undefined)).toThrow();
expect(Utils.getOrThrowIfEmpty(['a'])).toEqual(['a']);
});
});