UNPKG

@future-widget-lab/safe-ops

Version:

A set of helper functions for performing operations safely, preventing runtime errors from disrupting your application.

21 lines (19 loc) 449 B
import { attempt } from './attempt.helper'; describe('Unit | Helper | attempt', () => { it.each([ { input: () => { return 5; }, expected: { ok: true, error: null, result: 5 } }, { input: () => { throw new Error('Test'); }, expected: { ok: false, error: expect.any(Error), result: null } } ])('should return $expected given $input', ({ input, expected }) => { expect(attempt(input)).toEqual(expected); }); });