mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Avoid enforcing strict mode in _.defaults, _.extend, and _.bindAll and add benchmarks for _.bindAll and _.functions. [closes #45]
Former-commit-id: 1bb0b5155d3ae46052b4a06cb538dff307e8ec5e
This commit is contained in:
41
test/test.js
41
test/test.js
@@ -21,6 +21,9 @@
|
||||
_._ || _
|
||||
);
|
||||
|
||||
/** Shortcut used to make object properties immutable */
|
||||
var freeze = Object.freeze;
|
||||
|
||||
/** Shortcut used to convert array-like objects to arrays */
|
||||
var slice = [].slice;
|
||||
|
||||
@@ -52,9 +55,10 @@
|
||||
* Skips a given number of tests with a passing result.
|
||||
*
|
||||
* @private
|
||||
* @param {Number} count The number of tests to skip.
|
||||
* @param {Number} [count=1] The number of tests to skip.
|
||||
*/
|
||||
function skipTest(count) {
|
||||
count || (count = 1);
|
||||
while (count--) {
|
||||
ok(true, 'test skipped');
|
||||
}
|
||||
@@ -71,7 +75,7 @@
|
||||
if (window.document && window.require) {
|
||||
equal((lodashModule || {}).moduleName, 'lodash');
|
||||
} else {
|
||||
skipTest(1)
|
||||
skipTest()
|
||||
}
|
||||
});
|
||||
|
||||
@@ -79,7 +83,7 @@
|
||||
if (window.document && window.require) {
|
||||
equal((underscoreModule || {}).moduleName, 'underscore');
|
||||
} else {
|
||||
skipTest(1)
|
||||
skipTest()
|
||||
}
|
||||
});
|
||||
|
||||
@@ -87,7 +91,7 @@
|
||||
if (window.document) {
|
||||
notDeepEqual(lodashBadShim.keys({ 'a': 1 }), []);
|
||||
} else {
|
||||
skipTest(1);
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -209,6 +213,35 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
_.each(['bindAll', 'defaults', 'extend'], function(methodName) {
|
||||
var func = _[methodName];
|
||||
QUnit.module('lodash.' + methodName + ' strict mode checks');
|
||||
|
||||
test('should not throw strict mode errors', function() {
|
||||
var object = { 'a': null, 'b': function(){} },
|
||||
pass = true;
|
||||
|
||||
if (freeze) {
|
||||
freeze(object);
|
||||
try {
|
||||
if (methodName == 'bindAll') {
|
||||
func(object);
|
||||
} else {
|
||||
func(object, { 'a': 1 });
|
||||
}
|
||||
} catch(e) {
|
||||
pass = false;
|
||||
}
|
||||
ok(pass);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.find');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user