Skip to content

Commit

Permalink
Add test for incorrectly shimmed Object.create.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Oct 3, 2013
1 parent f68c262 commit 274f260
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
9 changes: 9 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
Function.prototype._bind = Function.prototype.bind;
Function.prototype.bind = function() { return function() {}; };

Object._create = Object.create;
Object.create = function() {};

Object._defineProperty = Object.defineProperty;
Object.defineProperty = function() {};

Expand All @@ -48,6 +51,11 @@
} else {
delete Function.prototype.bind;
}
if (Object._create) {
Object.create = Object._create;
} else {
delete Object.create;
}
if (Object._defineProperty) {
Object.defineProperty = Object._defineProperty;
} else {
Expand All @@ -60,6 +68,7 @@
}
delete Array._isArray;
delete Function.prototype._bind;
delete Object._create;
delete Object._defineProperty;
delete Object._keys;

Expand Down
29 changes: 24 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
}
});

test('avoids overwritten native methods', 3, function() {
test('avoids overwritten native methods', 4, function() {
function message(methodName) {
return '`_.' + methodName + '` should avoid overwritten native methods';
}
Expand All @@ -271,21 +271,40 @@
if (document) {
try {
var actual = lodashBadShim.bind(function() { return this.a; }, object)();
} catch(e) { }
} catch(e) {
actual = null;
}
ok(actual, message('bind'));

try {
actual = lodashBadShim.isArray([]);
} catch(e) { }
} catch(e) {
actual = null;
}
ok(actual, message('isArray'));

try {
actual = lodashBadShim.keys(object);
} catch(e) { }
} catch(e) {
actual = null;
}
deepEqual(actual, ['a'], message('keys'));

try {
var Foo = function() {
this.a = 2;
};

var actual = _.transform(new Foo, function(result, value, key) {
result[key] = value * value;
});
} catch(e) {
actual = null;
}
ok(actual instanceof Foo, message('transform'));
}
else {
skipTest(3);
skipTest(4);
}
});
}());
Expand Down

0 comments on commit 274f260

Please sign in to comment.