Skip to content

Commit

Permalink
implement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Jun 5, 2015
1 parent ea0181e commit 053ad51
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions test.js
Expand Up @@ -13,12 +13,30 @@ var fs = require('fs')
var test = require('assertit')
var alwaysThunk = require('./index')

// test('always-thunk:', function () {
// // body
// })
test('always-thunk:', function () {
test('should throw TypeError if not a function given', function (done) {
function fixture () {
alwaysThunk(12345)
}

var readFileSync = alwaysThunk(fs.readFileSync)
readFileSync('./package.json', 'utf8')(console.log)

var readFile = alwaysThunk(fs.readFile)
readFile('./package.json', 'utf8')(console.log)
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()
})
})
})

0 comments on commit 053ad51

Please sign in to comment.