Skip to content
Browse files

add defaulting of obj

  • Loading branch information...
1 parent 0d7c673 commit ce5af9ad2c15650d171a0a7e1affcd81a009f352 @tj tj committed Jul 17, 2012
Showing with 7 additions and 0 deletions.
  1. +1 −0 index.js
  2. +6 −0 test/only.js
View
1 index.js
@@ -1,5 +1,6 @@
module.exports = function(obj, keys){
+ obj = obj || {};
if ('string' == typeof keys) keys = keys.split(/ +/);
return keys.reduce(function(ret, key){
ret[key] = obj[key];
View
6 test/only.js
@@ -26,4 +26,10 @@ describe('only(obj, keys)', function(){
only(obj, 'name email last').should.eql(expected);
})
})
+
+ describe('when obj is missing', function(){
+ it('should default', function(){
+ only(null, 'foo').should.eql({ foo: undefined });
+ })
+ })
})

0 comments on commit ce5af9a

Please sign in to comment.
Something went wrong with that request. Please try again.