From 053ad51a5736fca9cc2e21105160de18d892a90a Mon Sep 17 00:00:00 2001 From: tunnckoCore Date: Sat, 6 Jun 2015 01:39:15 +0300 Subject: [PATCH] implement tests --- test.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/test.js b/test.js index 0a880b4..58914ee 100644 --- a/test.js +++ b/test.js @@ -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() + }) + }) +})