Add examples for schema tests

This commit is contained in:
Moreton Bay RC
2018-01-31 10:34:21 +10:00
parent b958945e8a
commit 8ed0a49ffd
+38
View File
@@ -261,3 +261,41 @@ setLocale({
number: { max: "Max message", min: "Min message" },
string: { email: "String message"}
});
interface MyInterface {
stringField: string;
numberField: number;
subFields: SubInterface;
}
interface SubInterface {
testField: string;
}
const typedSchema = yup.object<MyInterface>().shape({
stringField: yup.string().required(),
numberField: yup.number().required(),
subFields: yup.object<SubInterface>().shape({
testField: yup.string().required(),
}).required(),
});
const testObject = {
stringField: "test1",
numberField: 123,
subFields: {
testField: "test2"
},
};
typedSchema.validate(testObject);
const untypedSchema = yup.object().shape({
stringField: yup.string().required(),
numberField: yup.number().required(),
subFields: yup.object().shape({
testField: yup.string().required(),
}).required(),
});
untypedSchema.validate(testObject);