Skip to content

Instantly share code, notes, and snippets.

@smikes
Last active December 31, 2015 13:09
Show Gist options
  • Save smikes/7991102 to your computer and use it in GitHub Desktop.
Save smikes/7991102 to your computer and use it in GitHub Desktop.
function isBasicType(type, value) {
return type(value).valueOf() === value;
}
test('isBasicType works', function () {
assert.ok(isBasicType(Boolean, true));
assert.ok(isBasicType(Boolean, false));
assert.ok(isBasicType(Number, 1));
assert.ok(!isBasicType(Boolean, 0));
assert.ok(!isBasicType(Boolean, 1));
assert.ok(!isBasicType(Number, false));
assert.ok(!isBasicType(String, 1));
assert.ok(!isBasicType(Number, '1'));
});
test('hardcoded: example rc contains only valid options', function (done) {
var options = {
foo: Boolean,
bar: Number
},
example = {
foo: true,
bar: 3
},
keys;
keys = Object.keys(example);
keys.forEach(function(opt) {
assert.ok(options.hasOwnProperty(opt));
var type = options[opt],
value = example[opt];
assert.ok(isBasicType(type, value));
});
done();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment