-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathexception.test.ts
37 lines (35 loc) · 1.34 KB
/
exception.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
25
26
27
28
29
30
31
32
33
34
35
36
37
import { SealError } from '../implementation/exception'
import { SEALLibrary } from '../implementation/seal'
import SEAL from '../throws_wasm_node_umd'
let seal: SEALLibrary
beforeAll(async () => {
seal = await SEAL()
})
describe('Exception', () => {
test('It should be a static instance', () => {
expect(seal.Exception).toBeDefined()
expect(typeof seal.Exception.constructor).toBe('function')
expect(seal.Exception).toBeInstanceOf(Object)
expect(seal.Exception.constructor).toBe(Object)
expect(seal.Exception.constructor.name).toBe('Object')
})
test('It should have properties', () => {
expect(seal.Exception).toHaveProperty('safe')
})
test('It should attempt to get a safe error from an error instance', () => {
const spyOn = jest.spyOn(seal.Exception, 'safe')
const err = new Error('test error')
seal.Exception.safe(err as SealError)
expect(spyOn).toHaveBeenCalledWith(err)
})
test('It should attempt to get a safe error from a string', () => {
const spyOn = jest.spyOn(seal.Exception, 'safe')
seal.Exception.safe('unknown error')
expect(spyOn).toHaveBeenCalledWith('unknown error')
})
test('It should attempt to get a safe error from a "falsy" value', () => {
const spyOn = jest.spyOn(seal.Exception, 'safe')
seal.Exception.safe('')
expect(spyOn).toHaveBeenCalledWith('')
})
})