mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17: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.
60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
import assert from 'assert';
|
|
import lodashStable from 'lodash';
|
|
import { typedArrays, falsey, stubFalse, args, slice, symbol, realm } from './utils.js';
|
|
import isTypedArray from '../isTypedArray.js';
|
|
|
|
describe('isTypedArray', function() {
|
|
it('should return `true` for typed arrays', function() {
|
|
var expected = lodashStable.map(typedArrays, function(type) {
|
|
return type in root;
|
|
});
|
|
|
|
var actual = lodashStable.map(typedArrays, function(type) {
|
|
var Ctor = root[type];
|
|
return Ctor ? isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
});
|
|
|
|
it('should return `false` for non typed arrays', function() {
|
|
var expected = lodashStable.map(falsey, stubFalse);
|
|
|
|
var actual = lodashStable.map(falsey, function(value, index) {
|
|
return index ? isTypedArray(value) : isTypedArray();
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
|
|
assert.strictEqual(isTypedArray(args), false);
|
|
assert.strictEqual(isTypedArray([1, 2, 3]), false);
|
|
assert.strictEqual(isTypedArray(true), false);
|
|
assert.strictEqual(isTypedArray(new Date), false);
|
|
assert.strictEqual(isTypedArray(new Error), false);
|
|
assert.strictEqual(isTypedArray(_), false);
|
|
assert.strictEqual(isTypedArray(slice), false);
|
|
assert.strictEqual(isTypedArray({ 'a': 1 }), false);
|
|
assert.strictEqual(isTypedArray(1), false);
|
|
assert.strictEqual(isTypedArray(/x/), false);
|
|
assert.strictEqual(isTypedArray('a'), false);
|
|
assert.strictEqual(isTypedArray(symbol), false);
|
|
});
|
|
|
|
it('should work with typed arrays from another realm', function() {
|
|
if (realm.object) {
|
|
var props = lodashStable.invokeMap(typedArrays, 'toLowerCase');
|
|
|
|
var expected = lodashStable.map(props, function(key) {
|
|
return realm[key] !== undefined;
|
|
});
|
|
|
|
var actual = lodashStable.map(props, function(key) {
|
|
var value = realm[key];
|
|
return value ? isTypedArray(value) : false;
|
|
});
|
|
|
|
assert.deepStrictEqual(actual, expected);
|
|
}
|
|
});
|
|
});
|