-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
45 lines (36 loc) · 1.21 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
/*!
* native-promise-deferred <https://github.com/tunnckoCore/native-promise-deferred>
*
* 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 Deferred = require('./index')
test('should return a promise have `.resolve` and `.reject` methods too', function (done) {
var promise = Deferred()
test.strictEqual(typeof promise.then, 'function')
test.strictEqual(typeof promise.catch, 'function')
test.strictEqual(typeof promise.reject, 'function')
test.strictEqual(typeof promise.resolve, 'function')
done()
})
test('should resolve a value and handle it in .then method', function (done) {
var promise = new Deferred()
promise.then(function (res) {
test.strictEqual(res, 123)
done()
}, done).catch(done)
promise.resolve(123)
})
test('should `.catch` an error from rejected promise', function (done) {
var promise = new Deferred()
promise.catch(function (er) {
test.strictEqual(er instanceof Error, true)
test.strictEqual(er.name, 'TypeError')
test.strictEqual(er.message, 'foo bar baz')
done()
})
promise.reject(new TypeError('foo bar baz'))
})