Skip to content

Commit d70f662

Browse files
authored
fix round internal integer (#332)
1 parent 95de71a commit d70f662

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ function buildCode (location, code, laterCode, name) {
752752
`
753753
} else {
754754
code += `
755-
var t = Number(obj[${sanitized}])
755+
var t = $asInteger(obj[${sanitized}])
756756
if (!isNaN(t)) {
757757
${addComma}
758758
json += ${asString} + ':' + t

test/integer.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,15 @@ if (semver.gt(process.versions.node, '10.3.0')) {
137137
t.pass('Skip because Node version < 10.4')
138138
t.end()
139139
}
140+
141+
test('should round interger object parameter ', t => {
142+
t.plan(2)
143+
144+
const schema = { type: 'object', properties: { magic: { type: 'integer' } } }
145+
const validate = validator(schema)
146+
const stringify = build(schema, { rounding: 'ceil' })
147+
const output = stringify({ magic: 4.2 })
148+
149+
t.equal(output, '{"magic":5}')
150+
t.ok(validate(JSON.parse(output)), 'valid schema')
151+
})

0 commit comments

Comments
 (0)