mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Adjust mocking to ensure coverage in modularized builds.
This commit is contained in:
@@ -115,9 +115,6 @@
|
||||
setProperty(stringProto, '_contains', stringProto.contains);
|
||||
setProperty(stringProto, 'contains', stringProto._contains ? noop : Boolean);
|
||||
|
||||
setProperty(document, '_createDocumentFragment', document.createDocumentFragment);
|
||||
document.createDocumentFragment = noop;
|
||||
|
||||
setProperty(window, '_ArrayBuffer', window.ArrayBuffer);
|
||||
if (window.ArrayBuffer && window.Uint8Array) {
|
||||
ArrayBuffer = (function(_ArrayBuffer) {
|
||||
@@ -175,6 +172,10 @@
|
||||
};
|
||||
}(_parseInt)));
|
||||
|
||||
// fake lack of DOM support
|
||||
setProperty(document, '_createDocumentFragment', document.createDocumentFragment);
|
||||
document.createDocumentFragment = noop;
|
||||
|
||||
// fake `WinRTError`
|
||||
setProperty(window, 'WinRTError', Error);
|
||||
|
||||
@@ -224,11 +225,6 @@
|
||||
} else {
|
||||
delete stringProto.contains;
|
||||
}
|
||||
setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
|
||||
|
||||
document.createDocumentFragment = document._createDocumentFragment;
|
||||
setProperty(document, '_createDocumentFragment', undefined);
|
||||
|
||||
if (window._ArrayBuffer) {
|
||||
ArrayBuffer = _ArrayBuffer;
|
||||
}
|
||||
@@ -247,12 +243,17 @@
|
||||
setProperty(window, 'parseInt', window._parseInt);
|
||||
setProperty(window, '_parseInt', undefined);
|
||||
|
||||
document.createDocumentFragment = document._createDocumentFragment;
|
||||
setProperty(document, '_createDocumentFragment', undefined);
|
||||
|
||||
setProperty(window, 'WinRTError', undefined);
|
||||
|
||||
setProperty(window, 'exports', undefined);
|
||||
setProperty(window, 'global', undefined);
|
||||
setProperty(window, 'module', undefined);
|
||||
|
||||
setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
|
||||
|
||||
delete Array._isArray;
|
||||
delete Date._now;
|
||||
delete funcProto._method;
|
||||
|
||||
42
test/test.js
42
test/test.js
@@ -38,12 +38,10 @@
|
||||
noop = function() {},
|
||||
params = root.arguments,
|
||||
push = arrayProto.push,
|
||||
Set = root.Set,
|
||||
slice = arrayProto.slice,
|
||||
system = root.system,
|
||||
toString = objectProto.toString,
|
||||
Uint8Array = root.Uint8Array,
|
||||
WeakMap = root.WeakMap;
|
||||
Uint8Array = root.Uint8Array;
|
||||
|
||||
/** The file path of the Lo-Dash file to test */
|
||||
var filePath = (function() {
|
||||
@@ -119,6 +117,10 @@
|
||||
? require
|
||||
: (isJava && root.load) || noop;
|
||||
|
||||
/** Load ES6 Set and WeakMap shims */
|
||||
load('./asset/set.js');
|
||||
load('./asset/weakmap.js');
|
||||
|
||||
/** The unit testing framework */
|
||||
var QUnit = (function() {
|
||||
return root.QUnit || (
|
||||
@@ -340,9 +342,6 @@
|
||||
function createToString(funcName) {
|
||||
return _.constant(nativeString.replace(reToString, funcName));
|
||||
}
|
||||
// load ES6 Set and WeakMap shims
|
||||
require('./asset/set');
|
||||
require('./asset/weakmap');
|
||||
|
||||
// expose `baseEach` for better code coverage
|
||||
if (isModularize && !isNpm) {
|
||||
@@ -442,14 +441,11 @@
|
||||
};
|
||||
}()));
|
||||
|
||||
if (Set) {
|
||||
setProperty(root, 'Set', _.noop);
|
||||
}
|
||||
if (WeakMap) {
|
||||
setProperty(root, 'WeakMap', _.noop);
|
||||
}
|
||||
// fake `WinRTError`
|
||||
setProperty(root, 'WinRTError', Error);
|
||||
var _Set = root.Set;
|
||||
setProperty(root, 'Set', _.noop);
|
||||
|
||||
var _WeakMap = root.WeakMap;
|
||||
setProperty(root, 'WeakMap', _.noop);
|
||||
|
||||
// fake DOM
|
||||
setProperty(root, 'window', {});
|
||||
@@ -458,6 +454,9 @@
|
||||
return { 'nodeType': 11 };
|
||||
});
|
||||
|
||||
// fake `WinRTError`
|
||||
setProperty(root, 'WinRTError', Error);
|
||||
|
||||
// clear cache so Lo-Dash can be reloaded
|
||||
emptyObject(require.cache);
|
||||
|
||||
@@ -490,12 +489,12 @@
|
||||
} else {
|
||||
delete root.ArrayBuffer;
|
||||
}
|
||||
if (Set) {
|
||||
if (_Set) {
|
||||
setProperty(root, 'Set', Set);
|
||||
} else {
|
||||
delete root.Set;
|
||||
}
|
||||
if (WeakMap) {
|
||||
if (_WeakMap) {
|
||||
setProperty(root, 'WeakMap', WeakMap);
|
||||
} else {
|
||||
delete root.WeakMap;
|
||||
@@ -614,7 +613,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should avoid overwritten native methods', 14, function() {
|
||||
test('should avoid overwritten native methods', 15, function() {
|
||||
function Foo() {}
|
||||
|
||||
function message(lodashMethod, nativeMethod) {
|
||||
@@ -648,6 +647,13 @@
|
||||
ok(actual[0] instanceof Foo, message('_.create', 'Object.create'));
|
||||
deepEqual(actual[1], {}, message('_.create', 'Object.create'));
|
||||
|
||||
try {
|
||||
actual = lodashBizarro.curry(function(a, b) { return [a, b]; })(1)(2);
|
||||
} catch(e) {
|
||||
actual = null;
|
||||
}
|
||||
deepEqual(actual, [1, 2], message('_.curry', 'Object.defineProperty'));
|
||||
|
||||
try {
|
||||
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
|
||||
} catch(e) {
|
||||
@@ -716,7 +722,7 @@
|
||||
}
|
||||
}
|
||||
else {
|
||||
skipTest(14);
|
||||
skipTest(15);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user