addon-sdk/source/test/test-object.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-object.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +'use strict';
     1.8 +
     1.9 +const { merge, extend, has, each } = require('sdk/util/object');
    1.10 +
    1.11 +let o = {
    1.12 +  'paper': 0,
    1.13 +  'rock': 1,
    1.14 +  'scissors': 2
    1.15 +};
    1.16 +
    1.17 +//exports.testMerge = function(assert) {}
    1.18 +//exports.testExtend = function(assert) {}
    1.19 +
    1.20 +exports.testHas = function(assert) {
    1.21 +  assert.equal(has(o, 'paper'), true, 'has correctly finds key');
    1.22 +  assert.equal(has(o, 'rock'), true, 'has correctly finds key');
    1.23 +  assert.equal(has(o, 'scissors'), true, 'has correctly finds key');
    1.24 +  assert.equal(has(o, 'nope'), false, 'has correctly does not find key');
    1.25 +  assert.equal(has(o, '__proto__'), false, 'has correctly does not find key');
    1.26 +  assert.equal(has(o, 'isPrototypeOf'), false, 'has correctly does not find key');
    1.27 +};
    1.28 +
    1.29 +exports.testEach = function(assert) {
    1.30 +  var keys = new Set();
    1.31 +  each(o, function (value, key, object) {
    1.32 +    keys.add(key);
    1.33 +    assert.equal(o[key], value, 'Key and value pairs passed in');
    1.34 +    assert.equal(o, object, 'Object passed in');
    1.35 +  });
    1.36 +  assert.equal(keys.size, 3, 'All keys have been iterated upon');
    1.37 +};
    1.38 +
    1.39 +require('sdk/test').run(exports);

mercurial