UNPKG

dockest

Version:

Dockest is an integration testing tool aimed at alleviating the process of evaluating unit tests whilst running multi-container Docker applications.

115 lines 3.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const zod_1 = require("zod"); const custom_zod_error_map_1 = require("./custom-zod-error-map"); const Person = zod_1.z.object({ name: zod_1.z.string(), }); describe('customZodErrorMap', () => { it('should set the custom zod error map', () => { // with default error map expect(() => Person.parse({ name: 123 })).toThrowErrorMatchingInlineSnapshot(` "[ { "code": "invalid_type", "expected": "string", "received": "number", "path": [ "name" ], "message": "Expected string, received number" } ]" `); // with custom error map (0, custom_zod_error_map_1.setGlobalCustomZodErrorMap)(); expect(() => Person.parse({ name: 123 })).toThrowErrorMatchingInlineSnapshot(` "[ { "code": "invalid_type", "expected": "string", "received": "number", "path": [ "name" ], "message": "Expected string, received number [DATA]<123>" } ]" `); // reset -> back to default error map (0, custom_zod_error_map_1.resetGlobalCustomZodErrorMap)(); expect(() => Person.parse({ name: 123 })).toThrowErrorMatchingInlineSnapshot(` "[ { "code": "invalid_type", "expected": "string", "received": "number", "path": [ "name" ], "message": "Expected string, received number" } ]" `); // with custom error map (without data) (0, custom_zod_error_map_1.setGlobalCustomZodErrorMap)({ appendInputData: false }); expect(() => Person.parse({ name: 123 })).toThrowErrorMatchingInlineSnapshot(` "[ { "code": "invalid_type", "expected": "string", "received": "number", "path": [ "name" ], "message": "Expected string, received number" } ]" `); // reset -> back to default error map (0, custom_zod_error_map_1.resetGlobalCustomZodErrorMap)(); expect(() => Person.parse({ name: 123 })).toThrowErrorMatchingInlineSnapshot(` "[ { "code": "invalid_type", "expected": "string", "received": "number", "path": [ "name" ], "message": "Expected string, received number" } ]" `); // with custom error map (with data) expect(() => Person.parse({ name: 123 }, { errorMap: (0, custom_zod_error_map_1.customZodErrorMap)({ appendInputData: true }) })) .toThrowErrorMatchingInlineSnapshot(` "[ { "code": "invalid_type", "expected": "string", "received": "number", "path": [ "name" ], "message": "Expected string, received number [DATA]<123>" } ]" `); // the custom error map should not be set globally expect(() => Person.parse({ name: 123 })).toThrowErrorMatchingInlineSnapshot(` "[ { "code": "invalid_type", "expected": "string", "received": "number", "path": [ "name" ], "message": "Expected string, received number" } ]" `); }); }); //# sourceMappingURL=custom-zod-error-map.test.js.map