-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
65 lines (55 loc) · 1.48 KB
/
test.js
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
63
64
65
/*!
* dush-promise <https://github.com/tunnckoCore/dush-promise>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('mukla')
var promise = require('./index')
var dush = require('dush')
var app = dush().use(promise())
function fakePlugin (app) {
app.foo = function (val) {
if (val === 1) {
app.reject(new Error('foo bar'))
return app
}
app.bar = val
return app
}
return app
}
test('should app have `.resolve`, `.reject`, `.then` and `.catch` methods', function (done) {
test.strictEqual(typeof app.then, 'function')
test.strictEqual(typeof app.catch, 'function')
test.strictEqual(typeof app.reject, 'function')
test.strictEqual(typeof app.resolve, 'function')
done()
})
test('should emit `error` event when app.reject', function (done) {
app.use(fakePlugin)
app.on('error', function onError (er) {
test.strictEqual(er.message, 'foo bar')
done()
})
app.foo(1)
})
test('should pass error to `.catch` handler', function (done) {
app.use(fakePlugin)
app.foo(1)
app.catch(function (er) {
test.strictEqual(er instanceof Error, true)
test.strictEqual(er.message, 'foo bar')
done()
})
})
test('should handle value with `app.then` method', function (done) {
var emitter = dush().use(promise())
emitter.then(function (res) {
test.strictEqual(res, 123)
done()
})
emitter.resolve(123)
})