mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Cleanup lodashBizarro code to get coverage up in AMD modules.
This commit is contained in:
35
test/test.js
35
test/test.js
@@ -240,6 +240,7 @@
|
||||
(function() {
|
||||
if (!amd) {
|
||||
try {
|
||||
// add values from a different realm
|
||||
_.extend(_, require('vm').runInNewContext([
|
||||
'({',
|
||||
"'_arguments': (function() { return arguments; }(1, 2, 3)),",
|
||||
@@ -257,6 +258,9 @@
|
||||
'})'
|
||||
].join('\n')));
|
||||
|
||||
// load ES6 Set shim
|
||||
require('./asset/set');
|
||||
|
||||
// fake `WinRTError`
|
||||
setProperty(global, 'WinRTError', Error);
|
||||
|
||||
@@ -267,6 +271,12 @@
|
||||
return { 'nodeType': 11 };
|
||||
});
|
||||
|
||||
// allow bypassing native checks
|
||||
var _toString = Function.prototype.toString;
|
||||
setProperty(Function.prototype, 'toString', function() {
|
||||
return this === Set ? this.toString() : _toString.call(this);
|
||||
});
|
||||
|
||||
// add extensions
|
||||
Function.prototype._method = function() {};
|
||||
|
||||
@@ -301,8 +311,10 @@
|
||||
var _trimRight = String.prototype.trimRight;
|
||||
setProperty(String.prototype, 'trimRight', _trimRight ? function() {} : String);
|
||||
|
||||
// load Lo-Dash and expose it to the bad extensions/shims
|
||||
// clear cache so Lo-Dash can be reloaded
|
||||
emptyObject(require.cache);
|
||||
|
||||
// load Lo-Dash and expose it to the bad extensions/shims
|
||||
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro;
|
||||
|
||||
// restore native methods
|
||||
@@ -313,6 +325,8 @@
|
||||
setProperty(Object, 'getPrototypeOf', _getPrototypeOf);
|
||||
setProperty(Object, 'keys', _keys);
|
||||
|
||||
setProperty(Function.prototype, 'toString', _toString);
|
||||
|
||||
_.forOwn({
|
||||
'contains': _contains,
|
||||
'trim': _trim,
|
||||
@@ -435,7 +449,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should avoid overwritten native methods', 11, function() {
|
||||
test('should avoid overwritten native methods', 12, function() {
|
||||
function Foo() {}
|
||||
|
||||
function message(methodName) {
|
||||
@@ -443,6 +457,10 @@
|
||||
}
|
||||
var object = { 'a': true };
|
||||
|
||||
var largeArray = _.times(LARGE_ARRAY_SIZE, function() {
|
||||
return object;
|
||||
});
|
||||
|
||||
if (lodashBizarro) {
|
||||
try {
|
||||
actual = [lodashBizarro.isArray([]), lodashBizarro.isArray({ 'length': 0 })];
|
||||
@@ -487,6 +505,17 @@
|
||||
}
|
||||
deepEqual(actual, [['a'], []], message('Object.keys'));
|
||||
|
||||
try {
|
||||
actual = [
|
||||
lodashBizarro.difference([object], largeArray),
|
||||
lodashBizarro.intersection(largeArray, [object]),
|
||||
lodashBizarro.uniq(largeArray)
|
||||
];
|
||||
} catch(e) {
|
||||
actual = null;
|
||||
}
|
||||
deepEqual(actual, [[], [object], [object]], message('Set'));
|
||||
|
||||
try {
|
||||
actual = lodashBizarro.contains('abc', 'c');
|
||||
} catch(e) {
|
||||
@@ -509,7 +538,7 @@
|
||||
});
|
||||
}
|
||||
else {
|
||||
skipTest(11);
|
||||
skipTest(12);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user