UNPKG

@yoroi/banxa

Version:

The Banxa integration package of Yoroi SDK

42 lines (41 loc) 1.34 kB
import { handleZodErrors } from './zod-errors'; import { BanxaUnknownError, BanxaValidationError } from './errors'; import { z } from 'zod'; describe('handleZodErrors', () => { const testSchema = z.object({ name: z.string(), age: z.number() }); test('should convert a ZodError into a ValidationError', () => { const invalidData = { name: 123, age: 'John Doe' }; try { testSchema.parse(invalidData); } catch (error) { expect(error).toBeInstanceOf(z.ZodError); // Handle the error let handledError; try { handleZodErrors(error); } catch (e) { var _handledError; handledError = e; expect(handledError).toBeInstanceOf(BanxaValidationError); expect((_handledError = handledError) === null || _handledError === void 0 ? void 0 : _handledError.message).toBe('Invalid data: name: Expected string, received number, age: Expected number, received string'); } } }); test('should re-throw an error that is not a ZodError', () => { const someOtherError = new Error('Some other error'); let handledError; try { handleZodErrors(someOtherError); } catch (e) { handledError = e; } expect(handledError).toBeInstanceOf(BanxaUnknownError); }); }); //# sourceMappingURL=zod-errors.test.js.map