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.
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { _, stubTrue, MAX_INTEGER, stubFalse, falsey, args, symbol } from './utils.js';
|
|
|
|
describe('isInteger methods', function() {
|
|
lodashStable.each(['isInteger', 'isSafeInteger'], function(methodName) {
|
|
var func = _[methodName],
|
|
isSafe = methodName == 'isSafeInteger';
|
|
|
|
it('`_.' + methodName + '` should return `true` for integer values', function() {
|
|
var values = [-1, 0, 1],
|
|
expected = lodashStable.map(values, stubTrue);
|
|
|
|
var actual = lodashStable.map(values, function(value) {
|
|
return func(value);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
assert.strictEqual(func(MAX_INTEGER), !isSafe);
|
|
});
|
|
|
|
it('should return `false` for non-integer number values', function() {
|
|
var values = [NaN, Infinity, -Infinity, Object(1), 3.14],
|
|
expected = lodashStable.map(values, stubFalse);
|
|
|
|
var actual = lodashStable.map(values, function(value) {
|
|
return func(value);
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should return `false` for non-numeric values', function() {
|
|
var expected = lodashStable.map(falsey, function(value) {
|
|
return value === 0;
|
|
});
|
|
|
|
var actual = lodashStable.map(falsey, function(value, index) {
|
|
return index ? func(value) : func();
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
assert.strictEqual(func(args), false);
|
|
assert.strictEqual(func([1, 2, 3]), false);
|
|
assert.strictEqual(func(true), false);
|
|
assert.strictEqual(func(new Date), false);
|
|
assert.strictEqual(func(new Error), false);
|
|
assert.strictEqual(func({ 'a': 1 }), false);
|
|
assert.strictEqual(func(/x/), false);
|
|
assert.strictEqual(func('a'), false);
|
|
assert.strictEqual(func(symbol), false);
|
|
});
|
|
});
|
|
});
|