1var defaults = require('./'), 2 test = require('tap').test; 3 4test("ensure options is an object", function(t) { 5 var options = defaults(false, { a : true }); 6 t.ok(options.a); 7 t.end() 8}); 9 10test("ensure defaults override keys", function(t) { 11 var result = defaults({}, { a: false, b: true }); 12 t.ok(result.b, 'b merges over undefined'); 13 t.equal(result.a, false, 'a merges over undefined'); 14 t.end(); 15}); 16 17test("ensure defined keys are not overwritten", function(t) { 18 var result = defaults({ b: false }, { a: false, b: true }); 19 t.equal(result.b, false, 'b not merged'); 20 t.equal(result.a, false, 'a merges over undefined'); 21 t.end(); 22}); 23 24test("ensure defaults clone nested objects", function(t) { 25 var d = { a: [1,2,3], b: { hello : 'world' } }; 26 var result = defaults({}, d); 27 t.equal(result.a.length, 3, 'objects should be clones'); 28 t.ok(result.a !== d.a, 'objects should be clones'); 29 30 t.equal(Object.keys(result.b).length, 1, 'objects should be clones'); 31 t.ok(result.b !== d.b, 'objects should be clones'); 32 t.end(); 33}); 34 35