-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
47 lines (40 loc) · 1.15 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
/*!
* promise2thunk <https://github.com/tunnckoCore/promise2thunk>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('assertit')
var promise2thunk = require('./index')
var parseJson = require('then-parse-json')
test('promise2thunk:', function () {
test('should throw Error if not a Promise given', function (done) {
function fixture () {
promise2thunk(12345)
}
test.throws(fixture, Error)
test.throws(fixture, /promise2thunk expect a promise/)
done()
})
test('should convert promise to thunk', function (done) {
var promise = parseJson('{"foo":"bar"}')
var thunk = promise2thunk(promise)
thunk(function (err, res) {
test.ifError(err)
test.deepEqual(res, {foo: 'bar'})
done()
})
})
test('should handle errors', function (done) {
var promise = parseJson('foo~bar~baz')
var thunk = promise2thunk(promise)
thunk(function (err, res) {
test.ifError(!err)
test.ok(!res)
test.equal(err.message, 'Unexpected token o')
done()
})
})
})