mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
wip: code formatting nits continued
This commit is contained in:
64
test/isError.spec.js
Normal file
64
test/isError.spec.js
Normal file
@@ -0,0 +1,64 @@
|
||||
import lodashStable from 'lodash';
|
||||
|
||||
import {
|
||||
errors,
|
||||
stubTrue,
|
||||
CustomError,
|
||||
falsey,
|
||||
stubFalse,
|
||||
args,
|
||||
slice,
|
||||
symbol,
|
||||
realm,
|
||||
} from './utils';
|
||||
|
||||
import isError from '../src/isError';
|
||||
|
||||
describe('isError', () => {
|
||||
it('should return `true` for error objects', () => {
|
||||
const expected = lodashStable.map(errors, stubTrue);
|
||||
|
||||
const actual = lodashStable.map(errors, (error) => isError(error) === true);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should return `true` for subclassed values', () => {
|
||||
expect(isError(new CustomError('x'))).toBe(true);
|
||||
});
|
||||
|
||||
it('should return `false` for non error objects', () => {
|
||||
const expected = lodashStable.map(falsey, stubFalse);
|
||||
|
||||
const actual = lodashStable.map(falsey, (value, index) =>
|
||||
index ? isError(value) : isError(),
|
||||
);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
|
||||
expect(isError(args)).toBe(false);
|
||||
expect(isError([1, 2, 3])).toBe(false);
|
||||
expect(isError(true)).toBe(false);
|
||||
expect(isError(new Date())).toBe(false);
|
||||
expect(isError(slice)).toBe(false);
|
||||
expect(isError({ a: 1 })).toBe(false);
|
||||
expect(isError(1)).toBe(false);
|
||||
expect(isError(/x/)).toBe(false);
|
||||
expect(isError('a')).toBe(false);
|
||||
expect(isError(symbol)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return `false` for plain objects', () => {
|
||||
expect(isError({ name: 'Error', message: '' })).toBe(false);
|
||||
});
|
||||
|
||||
it('should work with an error object from another realm', () => {
|
||||
if (realm.errors) {
|
||||
const expected = lodashStable.map(realm.errors, stubTrue);
|
||||
|
||||
const actual = lodashStable.map(realm.errors, (error) => isError(error) === true);
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user