mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 12:27:49 +00:00
Enable testing fp/convert in the browser.
This commit is contained in:
@@ -44,11 +44,22 @@
|
|||||||
QUnitExtras.runInContext(root);
|
QUnitExtras.runInContext(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
var convert = root.fp || (function() {
|
var convert = (function() {
|
||||||
var baseConvert = load('../fp/_baseConvert.js');
|
var baseConvert = root.fp || load('../fp/_baseConvert.js');
|
||||||
|
if (!root.fp) {
|
||||||
return function(name, func, options) {
|
return function(name, func, options) {
|
||||||
return baseConvert(_, name, func, options);
|
return baseConvert(_, name, func, options);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
return function(name, func, options) {
|
||||||
|
if (typeof func != 'function') {
|
||||||
|
func = name;
|
||||||
|
name = undefined;
|
||||||
|
}
|
||||||
|
return name === undefined
|
||||||
|
? baseConvert(func, options)
|
||||||
|
: baseConvert(_.runInContext(), options)[name];
|
||||||
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
var mapping = root.mapping || load('../fp/_mapping.js'),
|
var mapping = root.mapping || load('../fp/_mapping.js'),
|
||||||
@@ -82,7 +93,8 @@
|
|||||||
QUnit.test('should accept an `options` argument', function(assert) {
|
QUnit.test('should accept an `options` argument', function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
if (!document) {
|
var array = [1, 2, 3, 4];
|
||||||
|
|
||||||
var remove = convert('remove', _.remove, {
|
var remove = convert('remove', _.remove, {
|
||||||
'cap': false,
|
'cap': false,
|
||||||
'curry': false,
|
'curry': false,
|
||||||
@@ -91,25 +103,18 @@
|
|||||||
'rearg': false
|
'rearg': false
|
||||||
});
|
});
|
||||||
|
|
||||||
var array = [1, 2, 3, 4];
|
var actual = remove(array, function(n, index) {
|
||||||
|
return index % 2 == 0;
|
||||||
var actual = remove(array, function(n) {
|
|
||||||
return n % 2 == 0;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(array, [1, 3]);
|
assert.deepEqual(array, [2, 4]);
|
||||||
assert.deepEqual(actual, [2, 4]);
|
assert.deepEqual(actual, [1, 3]);
|
||||||
assert.deepEqual(remove(), []);
|
assert.deepEqual(remove(), []);
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 3);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should respect the `cap` option', function(assert) {
|
QUnit.test('should respect the `cap` option', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var iteratee = convert('iteratee', _.iteratee, {
|
var iteratee = convert('iteratee', _.iteratee, {
|
||||||
'cap': false
|
'cap': false
|
||||||
});
|
});
|
||||||
@@ -119,31 +124,21 @@
|
|||||||
}, 3);
|
}, 3);
|
||||||
|
|
||||||
assert.deepEqual(func(1, 2, 3), [1, 2, 3]);
|
assert.deepEqual(func(1, 2, 3), [1, 2, 3]);
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should respect the `rearg` option', function(assert) {
|
QUnit.test('should respect the `rearg` option', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var add = convert('add', _.add, {
|
var add = convert('add', _.add, {
|
||||||
'rearg': true
|
'rearg': true
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(add('2')('1'), '12');
|
assert.strictEqual(add('2')('1'), '12');
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should use `options` in `runInContext`', function(assert) {
|
QUnit.test('should use `options` in `runInContext`', function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var runInContext = convert('runInContext', _.runInContext, {
|
var runInContext = convert('runInContext', _.runInContext, {
|
||||||
'cap': false,
|
'cap': false,
|
||||||
'curry': false,
|
'curry': false,
|
||||||
@@ -162,10 +157,6 @@
|
|||||||
assert.deepEqual(array, [1, 3]);
|
assert.deepEqual(array, [1, 3]);
|
||||||
assert.deepEqual(actual, [2, 4]);
|
assert.deepEqual(actual, [2, 4]);
|
||||||
assert.deepEqual(lodash.remove(), []);
|
assert.deepEqual(lodash.remove(), []);
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 3);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -356,7 +347,6 @@
|
|||||||
QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
|
QUnit.test('should provide the correct `iteratee` arguments', function(assert) {
|
||||||
assert.expect(4);
|
assert.expect(4);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var args,
|
var args,
|
||||||
array = [1, 2, 3],
|
array = [1, 2, 3],
|
||||||
object = { 'a': 1, 'b': 2 },
|
object = { 'a': 1, 'b': 2 },
|
||||||
@@ -390,16 +380,11 @@
|
|||||||
})(0, object);
|
})(0, object);
|
||||||
|
|
||||||
assert.deepEqual(args, isFIFO ? [0, 1] : [0, 2]);
|
assert.deepEqual(args, isFIFO ? [0, 1] : [0, 2]);
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 4);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should not support shortcut fusion', function(assert) {
|
QUnit.test('should not support shortcut fusion', function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var array = fp.range(0, LARGE_ARRAY_SIZE),
|
var array = fp.range(0, LARGE_ARRAY_SIZE),
|
||||||
filterCount = 0,
|
filterCount = 0,
|
||||||
mapCount = 0;
|
mapCount = 0;
|
||||||
@@ -427,10 +412,6 @@
|
|||||||
assert.deepEqual(combined(array), [4, 16]);
|
assert.deepEqual(combined(array), [4, 16]);
|
||||||
assert.strictEqual(filterCount, 200, 'filterCount');
|
assert.strictEqual(filterCount, 200, 'filterCount');
|
||||||
assert.strictEqual(mapCount, 200, 'mapCount');
|
assert.strictEqual(mapCount, 200, 'mapCount');
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 3);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -757,17 +738,12 @@
|
|||||||
|
|
||||||
var object = { 'a': 1 };
|
var object = { 'a': 1 };
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var extend = convert('extend', _.extend),
|
var extend = convert('extend', _.extend),
|
||||||
value = _.clone(object),
|
value = _.clone(object),
|
||||||
actual = extend(value, new Foo);
|
actual = extend(value, new Foo);
|
||||||
|
|
||||||
assert.deepEqual(value, object);
|
assert.deepEqual(value, object);
|
||||||
assert.deepEqual(actual, { 'a': 1, 'b': 2 });
|
assert.deepEqual(actual, { 'a': 1, 'b': 2 });
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 2);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -883,15 +859,10 @@
|
|||||||
QUnit.test('should convert by name', function(assert) {
|
QUnit.test('should convert by name', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var iteratee = convert('iteratee', _.iteratee),
|
var iteratee = convert('iteratee', _.iteratee),
|
||||||
func = iteratee(function(a, b, c) { return [a, b, c]; }, undefined, 3);
|
func = iteratee(function(a, b, c) { return [a, b, c]; }, undefined, 3);
|
||||||
|
|
||||||
assert.deepEqual(func(1, 2, 3), [1, undefined, undefined]);
|
assert.deepEqual(func(1, 2, 3), [1, undefined, undefined]);
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -1012,7 +983,6 @@
|
|||||||
QUnit.test('should convert by name', function(assert) {
|
QUnit.test('should convert by name', function(assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var object = { 'mixin': convert('mixin', _.mixin) };
|
var object = { 'mixin': convert('mixin', _.mixin) };
|
||||||
|
|
||||||
function Foo() {}
|
function Foo() {}
|
||||||
@@ -1024,10 +994,6 @@
|
|||||||
|
|
||||||
object.mixin(source);
|
object.mixin(source);
|
||||||
assert.strictEqual(typeof object.a, 'function');
|
assert.strictEqual(typeof object.a, 'function');
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert, 3);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
@@ -1054,7 +1020,6 @@
|
|||||||
QUnit.test('`_.' + methodName + '` should convert by name', function(assert) {
|
QUnit.test('`_.' + methodName + '` should convert by name', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var expected = isPartial ? [1, 2, 3] : [0, 1, 2],
|
var expected = isPartial ? [1, 2, 3] : [0, 1, 2],
|
||||||
par = convert(methodName, _[methodName]);
|
par = convert(methodName, _[methodName]);
|
||||||
|
|
||||||
@@ -1063,10 +1028,6 @@
|
|||||||
})([1, 2])(isPartial ? 3 : 0);
|
})([1, 2])(isPartial ? 3 : 0);
|
||||||
|
|
||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1156,13 +1117,8 @@
|
|||||||
QUnit.test('should convert by name', function(assert) {
|
QUnit.test('should convert by name', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
if (!document) {
|
|
||||||
var runInContext = convert('runInContext', _.runInContext);
|
var runInContext = convert('runInContext', _.runInContext);
|
||||||
assert.strictEqual(typeof runInContext({}).curryN, 'function');
|
assert.strictEqual(typeof runInContext({}).curryN, 'function');
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest(assert);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user