Brak opisu

test.js 1.0KB

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