UNPKG

validator-experimental-decorators

Version:
42 lines (41 loc) 1.86 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); describe("validatePositiveNumber", () => { class ExampleClass { processNumber(num) { return num; } } __decorate([ validatePositiveNumber ], ExampleClass.prototype, "processNumber", null); it("should allow positive numbers", () => { const example = new ExampleClass(); const result = example.processNumber(10); expect(result).toBe(10); // The result should be 10 }); it("should throw an error for negative numbers", () => { const example = new ExampleClass(); expect(() => { example.processNumber(-5); }).toThrowError("Invalid parameter value. Expected a positive number"); }); it("should throw an error for zero", () => { const example = new ExampleClass(); expect(() => { example.processNumber(0); }).toThrowError("Invalid parameter value. Expected a positive number"); }); it("should throw an error for non-numeric values", () => { const example = new ExampleClass(); expect(() => { example.processNumber("abc"); }).toThrowError("Invalid parameter value. Expected a positive number"); }); });