-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (28 loc) · 750 Bytes
/
test.js
File metadata and controls
36 lines (28 loc) · 750 Bytes
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
'use strict'
import test from 'ava'
import async from './index'
test('promise', async t => {
const fn = async(function * () {
return 'Hello ' + (yield new Promise(y => y('World'))) + (yield new Promise(y => y('!')))
})
t.is(await fn(), 'Hello World!')
})
test('error', async t => {
const fn = async(function * () {
const msg = yield new Promise(y => y('An error'))
throw new Error(msg)
})
t.throws(fn(), 'An error')
})
test('rejection', async t => {
const fn = async(function * () {
yield new Promise((y, n) => n(new Error('An error')))
})
t.throws(fn(), 'An error')
})
test('input validation', t => {
t.plan(3)
t.throws(() => async())
t.throws(() => async(function () { }))
t.notThrows(() => async(function * () {}))
})