generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathtoolkit-error.test.ts
More file actions
62 lines (50 loc) · 2.66 KB
/
toolkit-error.test.ts
File metadata and controls
62 lines (50 loc) · 2.66 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
56
57
58
59
60
61
62
import { AssemblyError, AuthenticationError, ContextProviderError, ToolkitError } from '../../src/api/toolkit-error';
describe('toolkit error', () => {
let toolkitError = new ToolkitError('Test toolkit error');
let authError = new AuthenticationError('Test authentication error');
let contextProviderError = new ContextProviderError('Test context provider error');
let assemblyError = AssemblyError.withStacks('Test authentication error', []);
let assemblyCauseError = AssemblyError.withCause('Test authentication error', new Error('other error'));
test('types are correctly assigned', async () => {
expect(toolkitError.type).toBe('toolkit');
expect(authError.type).toBe('authentication');
expect(assemblyError.type).toBe('assembly');
expect(assemblyCauseError.type).toBe('assembly');
expect(contextProviderError.type).toBe('context-provider');
});
test('isToolkitError works', () => {
expect(toolkitError.source).toBe('toolkit');
expect(ToolkitError.isToolkitError(toolkitError)).toBe(true);
expect(ToolkitError.isToolkitError(authError)).toBe(true);
expect(ToolkitError.isToolkitError(assemblyError)).toBe(true);
expect(ToolkitError.isToolkitError(assemblyCauseError)).toBe(true);
expect(ToolkitError.isToolkitError(contextProviderError)).toBe(true);
});
test('isAuthenticationError works', () => {
expect(authError.source).toBe('user');
expect(ToolkitError.isAuthenticationError(toolkitError)).toBe(false);
expect(ToolkitError.isAuthenticationError(authError)).toBe(true);
});
describe('isAssemblyError works', () => {
test('AssemblyError.fromStacks', () => {
expect(assemblyError.source).toBe('user');
expect(assemblyError.stacks).toStrictEqual([]);
expect(ToolkitError.isAssemblyError(assemblyError)).toBe(true);
expect(ToolkitError.isAssemblyError(toolkitError)).toBe(false);
expect(ToolkitError.isAssemblyError(authError)).toBe(false);
});
test('AssemblyError.fromCause', () => {
expect(assemblyCauseError.source).toBe('user');
expect((assemblyCauseError.cause as any)?.message).toBe('other error');
expect(ToolkitError.isAssemblyError(assemblyCauseError)).toBe(true);
expect(ToolkitError.isAssemblyError(toolkitError)).toBe(false);
expect(ToolkitError.isAssemblyError(authError)).toBe(false);
});
});
test('isContextProviderError works', () => {
expect(contextProviderError.source).toBe('user');
expect(ToolkitError.isContextProviderError(contextProviderError)).toBe(true);
expect(ToolkitError.isContextProviderError(toolkitError)).toBe(false);
expect(ToolkitError.isContextProviderError(authError)).toBe(false);
});
});