Skip to content

Instantly share code, notes, and snippets.

@reebalazs
Last active December 10, 2015 19:48
Show Gist options
  • Save reebalazs/4484168 to your computer and use it in GitHub Desktop.
Save reebalazs/4484168 to your computer and use it in GitHub Desktop.
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