fix(utils): fix error messages for range validation of number parameters (#10344)
This commit is contained in:
@@ -304,13 +304,13 @@ export const propChecker = (props, nextProps, objectList=[], ignoreList=[]) => {
|
|||||||
|
|
||||||
export const validateMaximum = ( val, max ) => {
|
export const validateMaximum = ( val, max ) => {
|
||||||
if (val > max) {
|
if (val > max) {
|
||||||
return `Value must be less than ${max}`
|
return `Value must be less than or equal to ${max}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const validateMinimum = ( val, min ) => {
|
export const validateMinimum = ( val, min ) => {
|
||||||
if (val < min) {
|
if (val < min) {
|
||||||
return `Value must be greater than ${min}`
|
return `Value must be greater than or equal to ${min}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,9 +147,9 @@ describe("utils", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("returns a message for invalid input", () => {
|
it("returns a message for invalid input", () => {
|
||||||
expect(validateMaximum(1, 0)).toEqual("Value must be less than 0")
|
expect(validateMaximum(1, 0)).toEqual("Value must be less than or equal to 0")
|
||||||
expect(validateMaximum(10, 9)).toEqual("Value must be less than 9")
|
expect(validateMaximum(10, 9)).toEqual("Value must be less than or equal to 9")
|
||||||
expect(validateMaximum(20, 19)).toEqual("Value must be less than 19")
|
expect(validateMaximum(20, 19)).toEqual("Value must be less than or equal to 19")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -160,9 +160,9 @@ describe("utils", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("returns a message for invalid input", () => {
|
it("returns a message for invalid input", () => {
|
||||||
expect(validateMinimum(-1, 0)).toEqual("Value must be greater than 0")
|
expect(validateMinimum(-1, 0)).toEqual("Value must be greater than or equal to 0")
|
||||||
expect(validateMinimum(1, 2)).toEqual("Value must be greater than 2")
|
expect(validateMinimum(1, 2)).toEqual("Value must be greater than or equal to 2")
|
||||||
expect(validateMinimum(10, 20)).toEqual("Value must be greater than 20")
|
expect(validateMinimum(10, 20)).toEqual("Value must be greater than or equal to 20")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -940,7 +940,7 @@ describe("utils", () => {
|
|||||||
maximum: 0
|
maximum: 0
|
||||||
}
|
}
|
||||||
value = 1
|
value = 1
|
||||||
assertValidateParam(param, value, ["Value must be less than 0"])
|
assertValidateParam(param, value, ["Value must be less than or equal to 0"])
|
||||||
|
|
||||||
// invalid number with minimum:0
|
// invalid number with minimum:0
|
||||||
param = {
|
param = {
|
||||||
@@ -949,7 +949,7 @@ describe("utils", () => {
|
|||||||
minimum: 0
|
minimum: 0
|
||||||
}
|
}
|
||||||
value = -10
|
value = -10
|
||||||
assertValidateParam(param, value, ["Value must be greater than 0"])
|
assertValidateParam(param, value, ["Value must be greater than or equal to 0"])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates optional numbers", () => {
|
it("validates optional numbers", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user