diff --git a/src/schemas/array/array-schema.spec.ts b/src/schemas/array/array-schema.spec.ts index 65b8099..09232ac 100644 --- a/src/schemas/array/array-schema.spec.ts +++ b/src/schemas/array/array-schema.spec.ts @@ -44,18 +44,16 @@ describe("Array Schema", () => { }); it("Should fail if array length is over maximum", () => { - expect( - arraySchema.max(1).validate([undefined, undefined, undefined]) - ).toEqual({ + expect(arraySchema.max(1).validate([undefined, undefined])).toEqual({ errors: true, - messagesTree: ["Must have less than 1 item"], + messagesTree: ["Cannot have more than 1 item"], }); }); it("Should fail if array length is below minimum", () => { expect(arraySchema.min(1).validate([])).toEqual({ errors: true, - messagesTree: ["Must have more than 1 item"], + messagesTree: ["Must have at least 1 item"], }); }); diff --git a/src/schemas/array/array-schema.ts b/src/schemas/array/array-schema.ts index d5b9c34..b294eba 100644 --- a/src/schemas/array/array-schema.ts +++ b/src/schemas/array/array-schema.ts @@ -48,7 +48,7 @@ class ArraySchemaImpl< const moreThanMaximumDefaultMessage = DefaultErrorMessagesManager.getDefaultMessages().array?.moreThanMaximum; - if (input.length <= this.minLength) { + if (input.length < this.minLength) { return { errors: true, messagesTree: [ @@ -60,14 +60,14 @@ class ArraySchemaImpl< }`, ], }; - } else if (input.length >= this.maxLength) { + } else if (input.length > this.maxLength) { return { errors: true, messagesTree: [ this.maxLengthMessage || (moreThanMaximumDefaultMessage && moreThanMaximumDefaultMessage(this.maxLength)) || - `Must not have more than ${this.maxLength} item${ + `Cannot have more than ${this.maxLength} item${ this.maxLength === 1 ? "" : "s" }`, ],