mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
* test: fix throttle.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix pickBy.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isBuffer.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix attempt.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix dropRightWhile.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix defer.spec.js and rest.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix invoke.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isArray.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix iteration-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix xor-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix property.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix ary.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix omit-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix debounce-and-throttle.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix unzip-and-zip.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix toPairs-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix exit-early.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: temporarily comment out takeWhile and dropWhile tests Signed-off-by: tison <wander4096@gmail.com> * test: partially fix union*.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix startsWith-and-endsWith.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isNil.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix some of syntax errors Signed-off-by: tison <wander4096@gmail.com> --------- Signed-off-by: tison <wander4096@gmail.com>
75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
import lodashStable from 'lodash';
|
|
import { slice, errors, stubTrue, CustomError, realm } from './utils';
|
|
import attempt from '../src/attempt';
|
|
|
|
describe('attempt', () => {
|
|
it('should return the result of `func`', () => {
|
|
expect(attempt(lodashStable.constant('x'))).toBe('x');
|
|
});
|
|
|
|
it('should provide additional arguments to `func`', () => {
|
|
const actual = attempt(
|
|
function () {
|
|
return slice.call(arguments);
|
|
},
|
|
1,
|
|
2,
|
|
);
|
|
expect(actual).toEqual([1, 2]);
|
|
});
|
|
|
|
it('should return the caught error', () => {
|
|
const expected = lodashStable.map(errors, stubTrue);
|
|
|
|
const actual = lodashStable.map(
|
|
errors,
|
|
(error) =>
|
|
attempt(() => {
|
|
throw error;
|
|
}) === error,
|
|
);
|
|
|
|
expect(actual).toEqual(expected);
|
|
});
|
|
|
|
it('should coerce errors to error objects', () => {
|
|
const actual = attempt(() => {
|
|
throw 'x';
|
|
});
|
|
expect(lodashStable.isEqual(actual, Error('x'))).toBeTruthy();
|
|
});
|
|
|
|
it('should preserve custom errors', () => {
|
|
const actual = attempt(() => {
|
|
throw new CustomError('x');
|
|
});
|
|
expect(actual instanceof CustomError);
|
|
});
|
|
|
|
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) =>
|
|
attempt(() => {
|
|
throw error;
|
|
}) === error,
|
|
);
|
|
|
|
expect(actual).toEqual(expected);
|
|
}
|
|
});
|
|
|
|
// FIXME: Work out a solution for _.
|
|
//
|
|
// it('should return an unwrapped value when implicitly chaining', () => {
|
|
// expect(_(lodashStable.constant('x')).attempt()).toBe('x');
|
|
// });
|
|
//
|
|
// it('should return a wrapped value when explicitly chaining', () => {
|
|
// expect(_(lodashStable.constant('x')).chain().attempt() instanceof _);
|
|
// });
|
|
});
|