-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.test.ts
More file actions
55 lines (47 loc) · 1.55 KB
/
index.test.ts
File metadata and controls
55 lines (47 loc) · 1.55 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
44
45
46
47
48
49
50
51
52
53
54
55
import {
throwError,
throwCustomError,
resolveValue,
MyAwesomeError,
rejectCustomError,
} from './index';
describe('resolveValue', () => {
test('should resolve provided value', async () => {
await expect(resolveValue('test value')).resolves.toBe('test value');
await expect(resolveValue(123)).resolves.toBe(123);
await expect(resolveValue(null)).resolves.toBeNull();
await expect(resolveValue(undefined)).resolves.toBeUndefined();
await expect(resolveValue({ key: 'value' })).resolves.toEqual({
key: 'value',
});
});
});
describe('throwError', () => {
const testMessage = 'Test error message';
test('should throw error with provided message', () => {
expect(() => throwError(testMessage)).toThrow(testMessage);
});
test('should throw error with default message if message is not provided', () => {
expect(() => throwError()).toThrow('Oops!');
});
});
describe('throwCustomError', () => {
test('should throw custom error', () => {
expect(() => throwCustomError()).toThrow(MyAwesomeError);
});
test('should contain correct error message', () => {
expect(() => throwCustomError()).toThrow(
'This is my awesome custom error!',
);
});
});
describe('rejectCustomError', () => {
test('should reject with MyAwesomeError instance', async () => {
await expect(rejectCustomError()).rejects.toThrow(MyAwesomeError);
});
test('should contain correct error message', async () => {
await expect(rejectCustomError()).rejects.toThrow(
'This is my awesome custom error!',
);
});
});