mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
wip: code formatting nits continued
This commit is contained in:
53
test/isTypedArray.spec.js
Normal file
53
test/isTypedArray.spec.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import lodashStable from 'lodash';
|
||||
import { typedArrays, falsey, stubFalse, args, slice, symbol, realm } from './utils';
|
||||
import isTypedArray from '../src/isTypedArray';
|
||||
|
||||
describe('isTypedArray', () => {
|
||||
it('should return `true` for typed arrays', () => {
|
||||
const expected = lodashStable.map(typedArrays, (type) => type in root);
|
||||
|
||||
const actual = lodashStable.map(typedArrays, (type) => {
|
||||
const Ctor = root[type];
|
||||
return Ctor ? isTypedArray(new Ctor(new ArrayBuffer(8))) : false;
|
||||
});
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should return `false` for non typed arrays', () => {
|
||||
const expected = lodashStable.map(falsey, stubFalse);
|
||||
|
||||
const actual = lodashStable.map(falsey, (value, index) =>
|
||||
index ? isTypedArray(value) : isTypedArray(),
|
||||
);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
|
||||
expect(isTypedArray(args)).toBe(false);
|
||||
expect(isTypedArray([1, 2, 3])).toBe(false);
|
||||
expect(isTypedArray(true)).toBe(false);
|
||||
expect(isTypedArray(new Date())).toBe(false);
|
||||
expect(isTypedArray(new Error())).toBe(false);
|
||||
expect(isTypedArray(slice)).toBe(false);
|
||||
expect(isTypedArray({ a: 1 })).toBe(false);
|
||||
expect(isTypedArray(1)).toBe(false);
|
||||
expect(isTypedArray(/x/)).toBe(false);
|
||||
expect(isTypedArray('a')).toBe(false);
|
||||
expect(isTypedArray(symbol)).toBe(false);
|
||||
});
|
||||
|
||||
it('should work with typed arrays from another realm', () => {
|
||||
if (realm.object) {
|
||||
const props = lodashStable.invokeMap(typedArrays, 'toLowerCase');
|
||||
|
||||
const expected = lodashStable.map(props, (key) => realm[key] !== undefined);
|
||||
|
||||
const actual = lodashStable.map(props, (key) => {
|
||||
const value = realm[key];
|
||||
return value ? isTypedArray(value) : false;
|
||||
});
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user