/*!
 * always-done <https://github.com/tunnckoCore/always-done>
 *
 * 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 alwaysDone = require('../index')

test('should throw TypeError if `callback` not function', function (done) {
  function fixture () {
    alwaysDone(function () {}, 123)
  }

  test.throws(fixture, TypeError)
  test.throws(fixture, /expect `callback` function/)
  done()
})

test('should returned error be passed to completion callback as `err`', function (done) {
  alwaysDone(function () {
    return new Error('foo bar baz')
  }, function (err, res) {
    test.ifError(!err)
    test.ok(err instanceof Error)
    test.equal(err.message, 'foo bar baz')
    test.equal(res, undefined)
    done()
  })
})

@@ -860,12 +860,361 @@
 e()%0A  %7D)%0A%7D)%0A
+%0Atest('should mute all errors and pass them to completion callback', function (done) %7B%0A  alwaysDone(function () %7B%0A    foobar // eslint-disable-line no-undef%0A    return 123%0A  %7D, function (err, res) %7B%0A    test.ifError(!err)%0A    test.ok(err instanceof Error)%0A    test.equal(err.name, 'ReferenceError')%0A    test.equal(res, undefined)%0A    done()%0A  %7D)%0A%7D)%0A

should mute all errors