-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgo.test.ts
More file actions
53 lines (46 loc) · 1.37 KB
/
go.test.ts
File metadata and controls
53 lines (46 loc) · 1.37 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
import { go } from './go'
describe('preforms go unit test', () => {
describe('async callback should return', () => {
test('null result if error thrown', async () => {
const [err, result] = await go(async () => {
throw new Error('test error')
})
expect(err).toBeInstanceOf(Error)
expect(result).toBeNull()
})
test('result if no error thrown', async () => {
const [err, result] = await go(async () => {
return 'test result'
})
expect(err).toBeNull()
expect(result).toBe('test result')
})
})
describe('sync callback should return', () => {
test('null result if error thrown', async () => {
const [err, result] = await go(() => {
throw new Error('test error')
})
expect(err).toBeInstanceOf(Error)
expect(result).toBeNull()
})
test('result if no error thrown', async () => {
const [err, result] = await go(() => {
return 'test result'
})
expect(err).toBeNull()
expect(result).toBe('test result')
})
})
test('should redeclare error during few executions', async () => {
let [err, result] = await go(async () => {
throw new Error('test error')
})
expect(err).toBeInstanceOf(Error)
expect(result).toBeNull()
;[err] = await go(async () => {
return 'success'
})
expect(err).toBeNull()
})
})