Skip to content

Commit

Permalink
Array schema implementation and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartmr committed Sep 1, 2021
1 parent b99bf3f commit 491cff3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/schemas/array/array-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/schemas/array/array-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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"
}`,
],
Expand Down

0 comments on commit 491cff3

Please sign in to comment.