IF else then test
Closed this issue · 3 comments
Hello, I do not understand why this test does not fail, thank you very much.
import * as Yup from "yup";
import { JSONSchema7 } from "json-schema";
import convertToYup from "../../src";
describe("convertToYup() number conditions", () => {
it("should validate other conditional", () => {
const schema: JSONSchema7 = {
type: "object",
$schema: "http://json-schema.org/draft-07/schema#",
$id: "test",
title: "Test",
properties: {
postcode: {
type: "number",
enum: [3000, 4000]
}
},
required: ["postcode"],
if: {
properties: { postcode: { type: "number", const: 3000 } }
},
then: {
properties: {
product: { type: "string", maxLength: 2 }
}
},
else: {
properties: {
product: { type: "string", maxLength: 1 }
}
}
};
const yupschema = convertToYup(schema) as Yup.ObjectSchema;
const data = {
postcode: 3000,
product: "ABC"
};
let isValid = yupschema.isValidSync(data);
expect(isValid).toBeTruthy();
});
});
@gustavodecarli, thanks for raising this issue. Looks to be related to how the number type is being interpreted. If you change the integers to string, it validates properly. I will look at trying to get a fix asap but if you need a quick workaround just change the integers to strings.
@gustavodecarli I've published a fix. Please install version 1.6.6-beta.0 and verify if it works?
Hi @ritchieanesco, I work with @gustavodecarli and I've been testing the beta version. Everything it seems to be ok! The if-them-else is now working properly. Let us know if you will be releasing a release version so we can take it. Thanks for the attention and for helping us with our issue!