Skip to content

Instantly share code, notes, and snippets.

@keis
Created March 31, 2015 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keis/11a3028eae3217214fc5 to your computer and use it in GitHub Desktop.
Save keis/11a3028eae3217214fc5 to your computer and use it in GitHub Desktop.
error matcher
var hamjest = require('hamjest')
, util = require('util')
, _ = require('lodash')
module.exports = error
function IsError(type, message) {
var prop = hamjest.hasProperty('message', message)
return _.create(new hamjest.TypeSafeMatcher(),
{ isExpectedType: function (actual) {
return actual instanceof Error &&
actual instanceof type
}
, matchesSafely: function (actual) {
return prop.matches(actual)
}
, describeMismatchSafely: function (actual, description) {
prop.describeMismatch(actual, description)
}
, describeTo: function (description) {
description.append('an error with a message that is ')
message.describeTo(description)
}
}
)
}
function error(type, message) {
if (util.isRegExp(message)) {
message = hamjest.matchesPattern(message)
}
return new IsError(type, message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment