test-object.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. 'use strict';
  5. const { merge, extend, has, each } = require('sdk/util/object');
  6. let o = {
  7. 'paper': 0,
  8. 'rock': 1,
  9. 'scissors': 2
  10. };
  11. //exports.testMerge = function(assert) {}
  12. //exports.testExtend = function(assert) {}
  13. exports.testHas = function(assert) {
  14. assert.equal(has(o, 'paper'), true, 'has correctly finds key');
  15. assert.equal(has(o, 'rock'), true, 'has correctly finds key');
  16. assert.equal(has(o, 'scissors'), true, 'has correctly finds key');
  17. assert.equal(has(o, 'nope'), false, 'has correctly does not find key');
  18. assert.equal(has(o, '__proto__'), false, 'has correctly does not find key');
  19. assert.equal(has(o, 'isPrototypeOf'), false, 'has correctly does not find key');
  20. };
  21. exports.testEach = function(assert) {
  22. var keys = new Set();
  23. each(o, function (value, key, object) {
  24. keys.add(key);
  25. assert.equal(o[key], value, 'Key and value pairs passed in');
  26. assert.equal(o, object, 'Object passed in');
  27. });
  28. assert.equal(keys.size, 3, 'All keys have been iterated upon');
  29. };
  30. require('sdk/test').run(exports);