mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
* Install test dependencies. * Add initial test files. These files were created using a simplistic AST manipulator using `recast` to preserve formatting. There's bound to be a huge chunk of errors, but this serves as a good start. QUnit was replaced with Mocha, with ES2015 imports running via `esm`. As far as possible, QUnit-specific syntax has been replaced with Mocha's `describe` and `it`, while the native Node.js `assert` module is used for assertions. Files in the `test` directory ending in `.test.js` will be treated as test files. * Add initial passing files to test run.
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { identity, empties, stubTrue, stubFalse } from './utils.js';
|
|
import every from '../every.js';
|
|
|
|
describe('every', function() {
|
|
it('should return `true` if `predicate` returns truthy for all elements', function() {
|
|
assert.strictEqual(lodashStable.every([true, 1, 'a'], identity), true);
|
|
});
|
|
|
|
it('should return `true` for empty collections', function() {
|
|
var expected = lodashStable.map(empties, stubTrue);
|
|
|
|
var actual = lodashStable.map(empties, function(value) {
|
|
try {
|
|
return every(value, identity);
|
|
} catch (e) {}
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should return `false` as soon as `predicate` returns falsey', function() {
|
|
var count = 0;
|
|
|
|
assert.strictEqual(every([true, null, true], function(value) {
|
|
count++;
|
|
return value;
|
|
}), false);
|
|
|
|
assert.strictEqual(count, 2);
|
|
});
|
|
|
|
it('should work with collections of `undefined` values (test in IE < 9)', function() {
|
|
assert.strictEqual(every([undefined, undefined, undefined], identity), false);
|
|
});
|
|
|
|
it('should use `_.identity` when `predicate` is nullish', function() {
|
|
var values = [, null, undefined],
|
|
expected = lodashStable.map(values, stubFalse);
|
|
|
|
var actual = lodashStable.map(values, function(value, index) {
|
|
var array = [0];
|
|
return index ? every(array, value) : every(array);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
expected = lodashStable.map(values, stubTrue);
|
|
actual = lodashStable.map(values, function(value, index) {
|
|
var array = [1];
|
|
return index ? every(array, value) : every(array);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should work with `_.property` shorthands', function() {
|
|
var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }];
|
|
assert.strictEqual(every(objects, 'a'), false);
|
|
assert.strictEqual(every(objects, 'b'), true);
|
|
});
|
|
|
|
it('should work with `_.matches` shorthands', function() {
|
|
var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }];
|
|
assert.strictEqual(every(objects, { 'a': 0 }), true);
|
|
assert.strictEqual(every(objects, { 'b': 1 }), false);
|
|
});
|
|
|
|
it('should work as an iteratee for methods like `_.map`', function() {
|
|
var actual = lodashStable.map([[1]], every);
|
|
assert.deepStrictEqual(actual, [true]);
|
|
});
|
|
});
|