Skip to content

Commit

Permalink
Changed error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartmr committed Jul 22, 2022
1 parent 3f6c1cf commit 9cb8fd0
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "not-me",
"version": "5.2.1",
"version": "5.3.0",
"description": "Easy and type-safe validation",
"main": "lib/index.js",
"types": "lib/types.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/array/array-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Array Schema", () => {
it("Should fail when input is not an array", () => {
expect(schema.validate(4)).toEqual({
errors: true,
messagesTree: ["Input must be an array"],
messagesTree: ["Must be an array"],
});
});

Expand All @@ -38,7 +38,7 @@ describe("Array Schema", () => {
errors: true,
messagesTree: [
{
2: [{ someProp: ["Input must be one of the allowed values"] }],
2: [{ someProp: ["Must be one of the allowed values"] }],
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/array/array-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ArraySchemaImpl<
message ||
DefaultErrorMessagesManager.getDefaultMessages().array
?.notAnArray ||
"Input must be an array",
"Must be an array",
],
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/base/base-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ describe("Base Schema", () => {

expect(undefinedRes).toEqual({
errors: true,
messagesTree: ["Input is required"],
messagesTree: ["Required"],
});

const nullRes = schema.validate(null);

expect(nullRes).toEqual({
errors: true,
messagesTree: ["Input is required"],
messagesTree: ["Required"],
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/schemas/base/base-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export abstract class BaseSchema<
message ||
DefaultErrorMessagesManager.getDefaultMessages().base
?.cannotBeUndefined ||
"Input must be defined",
"Cannot be undefined",
});
}

Expand All @@ -269,7 +269,7 @@ export abstract class BaseSchema<
message:
message ||
DefaultErrorMessagesManager.getDefaultMessages().base?.cannotBeNull ||
"Input cannot be null",
"Cannot be null",
});
}

Expand All @@ -279,7 +279,7 @@ export abstract class BaseSchema<
message:
message ||
DefaultErrorMessagesManager.getDefaultMessages().base?.isRequired ||
"Input is required",
"Required",
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/schemas/boolean/boolean-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BooleanSchemaImpl<
message ||
DefaultErrorMessagesManager.getDefaultMessages().boolean
?.notABoolean ||
"Input must be a true or false",
"Must be a boolean",
];

return {
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/date/date-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Date Schema", () => {

expect(schema.validate("abc")).toEqual({
errors: true,
messagesTree: ["Input is not a valid date"],
messagesTree: ["Invalid date"],
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/schemas/date/date-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class DateSchemaImpl<_Output = Date | undefined | null> extends BaseSchema<
const notADateMessages = [
message ||
DefaultErrorMessagesManager.getDefaultMessages().date?.notADate ||
"Input must be a date",
"Must be a date",
];

const invalidDateMessages = [
message ||
DefaultErrorMessagesManager.getDefaultMessages().date?.invalidDate ||
"Input is not a valid date",
"Invalid date",
];

if (input instanceof Date) {
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/equals/equals-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("Equals Schema", () => {

expect(result).toEqual({
errors: true,
messagesTree: ["Input must be one of the allowed values"],
messagesTree: ["Must be one of the allowed values"],
});
});
});
2 changes: 1 addition & 1 deletion src/schemas/equals/equals-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EqualsSchemaImpl<
message ||
DefaultErrorMessagesManager.getDefaultMessages().equals
?.notEqual ||
"Input must be one of the allowed values",
"Must be one of the allowed values",
],
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/number/number-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("Number Schema", () => {

expect(schema.validate("abc")).toEqual({
errors: true,
messagesTree: ["Input must be a number"],
messagesTree: ["Must be a number"],
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/schemas/number/number-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NumberSchemaImpl<_Output = number | undefined | null> extends BaseSchema<
const typeErrorMessage = [
message ||
DefaultErrorMessagesManager.getDefaultMessages().number?.notANumber ||
"Input must be a number",
"Must be a number",
];

if (typeof input === "number" || typeof input === "string") {
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/object/object-of-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("Object Of Schema", () => {
errors: true,
messagesTree: [
{
b: ["Input must be one of the allowed values"],
b: ["Must be one of the allowed values"],
},
],
});
Expand All @@ -38,7 +38,7 @@ describe("Object Of Schema", () => {

expect(result).toEqual({
errors: true,
messagesTree: ["Input must be an object"],
messagesTree: ["Must be an object"],
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/schemas/object/object-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Object Schema", () => {
errors: true,
messagesTree: [
{
a: ["Input must be an object"],
a: ["Must be an object"],
},
],
});
Expand All @@ -40,7 +40,7 @@ describe("Object Schema", () => {

expect(result).toEqual({
errors: true,
messagesTree: [{ a: ["Input is required"] }],
messagesTree: [{ a: ["Required"] }],
});
});

Expand All @@ -53,7 +53,7 @@ describe("Object Schema", () => {

expect(result).toEqual({
errors: true,
messagesTree: [{ a: ["Input must be a string"] }],
messagesTree: [{ a: ["Must be a string"] }],
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/schemas/object/object-schema.union.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe("Object Schema - Union", () => {
errors: true,
messagesTree: [
{
d: ["Input is required"],
d: ["Required"],
},
],
});
Expand All @@ -98,7 +98,7 @@ describe("Object Schema - Union", () => {
errors: true,
messagesTree: [
{
d: ["Input must be one of the allowed values"],
d: ["Must be one of the allowed values"],
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/object/object-type-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function objectTypeFilter(
message ||
DefaultErrorMessagesManager.getDefaultMessages().object
?.notAnObject ||
"Input must be an object",
"Must be an object",
],
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/schemas/or/or-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ describe("Or Schema", () => {
messagesTree: expect.any(Array) as unknown,
});
});

it("Should throw when schemas are not provided on declaration", () => {
expect(() => {
or([] as unknown as [Schema<unknown>]).required();
}).toThrow("No schemas provided");
});
});
2 changes: 1 addition & 1 deletion src/schemas/string/string-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("String Schema", () => {

expect(schema.validate({})).toEqual({
errors: true,
messagesTree: ["Input must be a string"],
messagesTree: ["Must be a string"],
});
});
});
2 changes: 1 addition & 1 deletion src/schemas/string/string-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class StringSchemaImpl<
message ||
DefaultErrorMessagesManager.getDefaultMessages().string
?.notAString ||
"Input must be a string",
"Must be a string",
];

return {
Expand Down

0 comments on commit 9cb8fd0

Please sign in to comment.