Created
March 31, 2015 17:00
-
-
Save keis/11a3028eae3217214fc5 to your computer and use it in GitHub Desktop.
error matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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