Last active
December 10, 2015 19:48
-
-
Save reebalazs/4484168 to your computer and use it in GitHub Desktop.
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
buster.assertions.add('keys', { | |
assert: function (actual, keys) { | |
var keyMap = {}; | |
var keyCnt = 0; | |
for (var i=0; i<keys.length; i++) { | |
keyMap[keys[i]] = true; | |
keyCnt += 1; | |
} | |
for (var key in actual) { | |
if (actual.hasOwnProperty(key)) { | |
if (! keyMap[key]) { | |
return false; | |
} | |
keyCnt -= 1; | |
} | |
} | |
return keyCnt === 0; | |
}, | |
assertMessage: "Expected ${0} to have exact keys ${1}!", | |
refuteMessage: "Expected ${0} not to have exact keys ${1}!" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment