Skip to content

Commit

Permalink
add more tests, close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Jun 8, 2015
1 parent f497726 commit 5ffacbd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,39 @@ test('make-callback:', function () {
test('should pass result to callback', function (done) {
var JSONParseAsync = makeCallback(JSON.parse)

JSONParseAsync('{"foo":"bar"}', function (err, json) {
JSONParseAsync('{"foo":"bar"}', function (err, res) {
test.ifError(err)
test.deepEqual(json, {foo: 'bar'})
test.deepEqual(res, {foo: 'bar'})
done()
})
})
test('should pass error to callback', function (done) {
var JSONParseAsync = makeCallback(JSON.parse)

JSONParseAsync('foo bar baz', function (err, json) {
JSONParseAsync('foo bar baz', function (err) {
test.ok(err)
test.ifError(!err)
test.equal(err.message, 'Unexpected token o')
done()
})
})
test('should pass contents of file to callback (when readFileSync)', function (done) {
var readFile = makeCallback(fs.readFileSync)

readFile('./package.json', 'utf8', function (err, res) {
test.ifError(err)
test.ok(res.indexOf('tunnckoCore/make-callback') !== -1)
done()
})
})
test('should pass errors to callback (when readFileSync)', function (done) {
var readFile = makeCallback(fs.readFileSync)

readFile('./packdsgfdfgdfgage.json', 'utf8', function (err, res) {
test.ifError(!err)
test.equal(err.code, 'ENOENT')
test.ok(err.message.indexOf('no such file') !== -1)
done()
})
})
})

0 comments on commit 5ffacbd

Please sign in to comment.