Skip to content

Commit

Permalink
Merge pull request #45 from adityabakle/master
Browse files Browse the repository at this point in the history
Rename should throw an error for invalid property .
  • Loading branch information
Eran Hammer committed Mar 19, 2014
2 parents 2c1f341 + 3bdfbd4 commit 7b14ca4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -437,6 +437,7 @@ exports.loadDirModules = function (path, excludeFiles, target) { // target(

exports.rename = function (obj, from, to) {

exports.assert(obj.hasOwnProperty(from),'Invalid property',from);
obj[to] = obj[from];
delete obj[from];
};
Expand Down
12 changes: 12 additions & 0 deletions test/index.js
Expand Up @@ -942,6 +942,18 @@ describe('Hoek', function () {
expect(a.x).to.equal('c');
done();
});

it('should throw and invalid key in object error', function (done) {

var fn = function () {

var obj = {a:1, b:2};
Hoek.rename(obj, 'd', 'a');
};

expect(fn).to.throw('Invalid property d');
done();
});
});

describe('Timer', function () {
Expand Down

0 comments on commit 7b14ca4

Please sign in to comment.