Skip to content

Commit 74cf591

Browse files
committed
Fixed test coverage to match 100%
1 parent 7415e55 commit 74cf591

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/validation/__tests__/number.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ it('validates that a given number is higher then the min value', () => {
1818
expect(number(value, { min: 9 })).toEqual(true)
1919
expect(number(value, { min: 11 })).toEqual(false)
2020
})
21+
22+
it('validates tht a given number is between the given range', () => {
23+
const value = 10
24+
25+
expect(number(value, { min: 9, max: 11 })).toEqual(true)
26+
expect(number(value, { min: 8, max: 9 })).toEqual(false)
27+
})

src/validation/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
function number(x, { max, min } = {}) {
2-
if (min || max) {
3-
if (Number(x) === x) {
4-
if (x >= min && x <= max) return true
5-
if (x >= min && max === undefined) return true
6-
if (x <= max && min === undefined) return true
7-
}
2+
if ((min || max) && Number(x) === x) {
3+
if (x >= min && x <= max) return true
4+
if (x >= min && max === undefined) return true
5+
if (x <= max && min === undefined) return true
86
}
97

108
if (Number(x) === x && min === undefined && max === undefined) {

0 commit comments

Comments
 (0)