-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
42 lines (37 loc) · 1.17 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
/*!
* always-thunk <https://github.com/tunnckoCore/always-thunk>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var fs = require('fs')
var test = require('assertit')
var alwaysThunk = require('./index')
test('always-thunk:', function () {
test('should throw TypeError if not a function given', function (done) {
function fixture () {
alwaysThunk(12345)
}
test.throws(fixture, TypeError)
test.throws(fixture, /always-thunk expect a function/)
done()
})
test('should transform sync function to thunk', function (done) {
var readFileSync = alwaysThunk(fs.readFileSync)
readFileSync('./package.json', 'utf8')(function (err, res) {
test.ifError(err)
test.ok(res.indexOf('tunnckoCore/always-thunk') !== -1)
done()
})
})
test('should transform asynchronous function to thunk', function (done) {
var readFile = alwaysThunk(fs.readFile)
readFile('./package.json', 'utf8')(function (err, res) {
test.ifError(err)
test.ok(res.indexOf('tunnckoCore/always-thunk') !== -1)
done()
})
})
})