blob: 73a2c60d346665991f923df29c59417b0bff30c6 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
var test = require('prova');
var addAttributes = require('../../../src/lib/add-attributes');
test('addAttributes', function(t) {
// Normal Cases: add nothing, add 1 thing, add multiple things
var obj = {};
addAttributes(obj, {});
t.deepEqual(obj, {});
addAttributes(obj, {a: 'a'});
t.deepEqual(obj, {a: 'a'});
addAttributes(obj, {b: 'b'});
t.deepEqual(obj, {a: 'a', b: 'b'});
addAttributes(obj, {c: [3], d: function() { return 'd'; }});
var expected = {a: 'a', b: 'b', c: [3], d: function() { return 'd'; }};
for (var key1 in obj) {
if (obj.hasOwnProperty(key1)) {
t.ok('' + obj[key1] === '' + expected[key1]); // effectively equal
}
}
// We don't replace existing attributes
addAttributes(obj, {a: 'will not replace'});
for (var key2 in obj) {
if (obj.hasOwnProperty(key2)) {
t.ok('' + obj[key2] === '' + expected[key2]); // effectively equal
}
}
t.end();
});