Adjust mocking to ensure coverage in modularized builds.

This commit is contained in:
John-David Dalton
2014-08-26 09:33:03 -07:00
parent cc4fdfd852
commit 81d0d5c59f
2 changed files with 33 additions and 26 deletions

View File

@@ -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);
}
});
}());