UNPKG

@yoroi/exchange

Version:

The Exchange package of Yoroi SDK

43 lines (41 loc) 1.34 kB
"use strict"; var _types = require("@yoroi/types"); var _zod = require("zod"); var _getValidationError = require("./get-validation-error"); describe('getValidationError', () => { const testSchema = _zod.z.object({ name: _zod.z.string(), age: _zod.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(_zod.z.ZodError); // Handle the error let handledError; try { throw (0, _getValidationError.getValidationError)(error); } catch (e) { handledError = e; expect(handledError).toBeInstanceOf(_types.Exchange.Errors.Validation); expect(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 { throw (0, _getValidationError.getValidationError)(someOtherError); } catch (e) { handledError = e; } expect(handledError).toBeInstanceOf(Error); }); }); //# sourceMappingURL=get-validation-error.test.js.map