pakmanaged.js
function assertThrows (constructor, errMsg, msg) {
        if (msg) flag(this, 'message', msg);
        var obj = flag(this, 'object');
        new Assertion(obj, msg).is.a('function');
    
        var thrown = false
          , desiredError = null
          , name = null
          , thrownError = null;
    
        if (arguments.length === 0) {
          errMsg = null;
          constructor = null;
        } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
          errMsg = constructor;
          constructor = null;
        } else if (constructor && constructor instanceof Error) {
          desiredError = constructor;
          constructor = null;
          errMsg = null;
        } else if (typeof constructor === 'function') {
          name = constructor.prototype.name || constructor.name;
          if (name === 'Error' && constructor !== Error) {
            name = (new constructor()).name;
          }
        } else {
          constructor = null;
        }
    
        try {
          obj();
        } catch (err) {
          // first, check desired error
          if (desiredError) {
            this.assert(
                err === desiredError
              , 'expected #{this} to throw #{exp} but #{act} was thrown'
              , 'expected #{this} to not throw #{exp}'
              , (desiredError instanceof Error ? desiredError.toString() : desiredError)
              , (err instanceof Error ? err.toString() : err)
            );
    
            flag(this, 'object', err);
            return this;
          }
    
          // next, check constructor
          if (constructor) {
            this.assert(
                err instanceof constructor
              , 'expected #{this} to throw #{exp} but #{act} was thrown'
              , 'expected #{this} to not throw #{exp} but #{act} was thrown'
              , name
              , (err instanceof Error ? err.toString() : err)
            );
    
            if (!errMsg) {
              flag(this, 'object', err);
              return this;
            }
          }
    
          // next, check message
          var message = 'error' === _.type(err) && "message" in err
            ? err.message
            : '' + err;
    
          if ((message != null) && errMsg && errMsg instanceof RegExp) {
            this.assert(
                errMsg.exec(message)
              , 'expected #{this} to throw error matching #{exp} but got #{act}'
              , 'expected #{this} to throw error not matching #{exp}'
              , errMsg
              , message
            );
    
            flag(this, 'object', err);
            return this;
          } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
            this.assert(
                ~message.indexOf(errMsg)
              , 'expected #{this} to throw error including #{exp} but got #{act}'
              , 'expected #{this} to throw error not including #{act}'
              , errMsg
              , message
            );
    
            flag(this, 'object', err);
            return this;
          } else {
            thrown = true;
            thrownError = err;
          }
        }
    
        var actuallyGot = ''
          , expectedThrown = name !== null
            ? name
            : desiredError
              ? '#{exp}' //_.inspect(desiredError)
              : 'an error';
    
        if (thrown) {
          actuallyGot = ' but #{act} was thrown'
        }
    
        this.assert(
            thrown === true
          , 'expected #{this} to throw ' + expectedThrown + actuallyGot
          , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
          , (desiredError instanceof Error ? desiredError.toString() : desiredError)
          , (thrownError instanceof Error ? thrownError.toString() : thrownError)
        );
    
        flag(this, 'object', thrownError);
      }
function assertThrows (constructor, errMsg, msg) {
        if (msg) flag(this, 'message', msg);
        var obj = flag(this, 'object');
        new Assertion(obj, msg).is.a('function');
    
        var thrown = false
          , desiredError = null
          , name = null
          , thrownError = null;
    
        if (arguments.length === 0) {
          errMsg = null;
          constructor = null;
        } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
          errMsg = constructor;
          constructor = null;
        } else if (constructor && constructor instanceof Error) {
          desiredError = constructor;
          constructor = null;
          errMsg = null;
        } else if (typeof constructor === 'function') {
          name = constructor.prototype.name || constructor.name;
          if (name === 'Error' && constructor !== Error) {
            name = (new constructor()).name;
          }
        } else {
          constructor = null;
        }
    
        try {
          obj();
        } catch (err) {
          // first, check desired error
          if (desiredError) {
            this.assert(
                err === desiredError
              , 'expected #{this} to throw #{exp} but #{act} was thrown'
              , 'expected #{this} to not throw #{exp}'
              , (desiredError instanceof Error ? desiredError.toString() : desiredError)
              , (err instanceof Error ? err.toString() : err)
            );
    
            flag(this, 'object', err);
            return this;
          }
    
          // next, check constructor
          if (constructor) {
            this.assert(
                err instanceof constructor
              , 'expected #{this} to throw #{exp} but #{act} was thrown'
              , 'expected #{this} to not throw #{exp} but #{act} was thrown'
              , name
              , (err instanceof Error ? err.toString() : err)
            );
    
            if (!errMsg) {
              flag(this, 'object', err);
              return this;
            }
          }
    
          // next, check message
          var message = 'error' === _.type(err) && "message" in err
            ? err.message
            : '' + err;
    
          if ((message != null) && errMsg && errMsg instanceof RegExp) {
            this.assert(
                errMsg.exec(message)
              , 'expected #{this} to throw error matching #{exp} but got #{act}'
              , 'expected #{this} to throw error not matching #{exp}'
              , errMsg
              , message
            );
    
            flag(this, 'object', err);
            return this;
          } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
            this.assert(
                ~message.indexOf(errMsg)
              , 'expected #{this} to throw error including #{exp} but got #{act}'
              , 'expected #{this} to throw error not including #{act}'
              , errMsg
              , message
            );
    
            flag(this, 'object', err);
            return this;
          } else {
            thrown = true;
            thrownError = err;
          }
        }
    
        var actuallyGot = ''
          , expectedThrown = name !== null
            ? name
            : desiredError
              ? '#{exp}' //_.inspect(desiredError)
              : 'an error';
    
        if (thrown) {
          actuallyGot = ' but #{act} was thrown'
        }
    
        this.assert(
            thrown === true
          , 'expected #{this} to throw ' + expectedThrown + actuallyGot
          , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
          , (desiredError instanceof Error ? desiredError.toString() : desiredError)
          , (thrownError instanceof Error ? thrownError.toString() : thrownError)
        );
    
        flag(this, 'object', thrownError);
      }
### .throw(constructor)

Asserts that the function target will throw a specific error, or specific type of error
(as determined using `instanceof`), optionally with a RegExp or string inclusion test
for the error's message.

var err = new ReferenceError('This is a bad function.');
var fn = function () { throw err; }
expect(fn).to.throw(ReferenceError);
expect(fn).to.throw(Error);
expect(fn).to.throw(/bad function/);
expect(fn).to.not.throw('good function');
expect(fn).to.throw(ReferenceError, /bad function/);
expect(fn).to.throw(err);
expect(fn).to.not.throw(new RangeError('Out of range.'));

Please note that when a throw expectation is negated, it will check each
parameter independently, starting with error constructor type. The appropriate way
to check for the existence of a type of error but for a message that does not match
is to use `and`.

expect(fn).to.throw(ReferenceError)
.and.not.throw(/good function/);

@name throw
@alias throws
@alias Throw
@param {ErrorConstructor} constructor
@param {String|RegExp} expected error message
@param {String} message _optional_
@see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
@returns error for chaining (null if no error)
@api public