mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
added tests for ValidationError instance and static methods and properties
This commit is contained in:
+21
-14
@@ -77,12 +77,21 @@ const renderable = yup.lazy(value => {
|
||||
});
|
||||
const renderables = yup.array().of(renderable);
|
||||
|
||||
// ValidationError static methods
|
||||
// $ExpectType boolean
|
||||
ValidationError.isError(new ValidationError("error", "value", "path"));
|
||||
// $ExpectType string | ((params?: any) => string)
|
||||
ValidationError.formatError("error", { path: "path" });
|
||||
ValidationError.formatError("error");
|
||||
ValidationError.formatError(() => "error");
|
||||
ValidationError.formatError(() => "error", { path: "path" });
|
||||
|
||||
// ValidationError
|
||||
let error: ValidationError = yup.ValidationError("error", "value", "path");
|
||||
error = yup.ValidationError(["error", "error2"], true, "path");
|
||||
error = yup.ValidationError(["error", "error2"], 5, "path");
|
||||
error = yup.ValidationError(["error", "error2"], { name: "value" }, "path");
|
||||
error = yup.ValidationError(
|
||||
let error: ValidationError = new yup.ValidationError("error", "value", "path");
|
||||
error = new yup.ValidationError(["error", "error2"], true, "path");
|
||||
error = new yup.ValidationError(["error", "error2"], 5, "path");
|
||||
error = new yup.ValidationError(["error", "error2"], { name: "value" }, "path");
|
||||
error = new yup.ValidationError(
|
||||
["error", "error2"],
|
||||
{ name: "value" },
|
||||
"path",
|
||||
@@ -93,7 +102,7 @@ error = {
|
||||
message: "error",
|
||||
path: "path",
|
||||
errors: ["error"],
|
||||
inner: [yup.ValidationError("error", true, "path")],
|
||||
inner: [new yup.ValidationError("error", true, "path")],
|
||||
type: "date",
|
||||
value: { start: "2017-11-10" }
|
||||
};
|
||||
@@ -135,8 +144,8 @@ mixed.default(() => ({ number: 5 }));
|
||||
mixed.default();
|
||||
mixed.nullable(true);
|
||||
mixed.required();
|
||||
mixed.required('Foo');
|
||||
mixed.required(() => 'Foo');
|
||||
mixed.required("Foo");
|
||||
mixed.required(() => "Foo");
|
||||
mixed.notRequired(); // $ExpectType MixedSchema
|
||||
mixed.typeError("type error");
|
||||
mixed.typeError(() => "type error");
|
||||
@@ -155,10 +164,8 @@ mixed
|
||||
then: yup.number().min(5),
|
||||
otherwise: yup.number().min(0)
|
||||
})
|
||||
.when(
|
||||
"$other",
|
||||
(value: any, schema: MixedSchema) =>
|
||||
value === 4 ? schema.required() : schema
|
||||
.when("$other", (value: any, schema: MixedSchema) =>
|
||||
value === 4 ? schema.required() : schema
|
||||
);
|
||||
// tslint:disable-next-line:no-invalid-template-strings
|
||||
mixed.test("is-jimmy", "${path} is not Jimmy", value => value === "jimmy");
|
||||
@@ -486,8 +493,8 @@ interface ExpectedABC {
|
||||
}
|
||||
|
||||
const expectedAbc: ExpectedABC = {
|
||||
a: 'qwerty',
|
||||
b: 'asdfg',
|
||||
a: "qwerty",
|
||||
b: "asdfg",
|
||||
c: 123
|
||||
};
|
||||
const actualAbc: yup.Shape<AB, BC> = expectedAbc;
|
||||
|
||||
Reference in New Issue
Block a user