Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,8 @@ function buildArray (context, location) {
`
}

if (largeArrayMechanism !== 'default') {
if (largeArrayMechanism === 'json-stringify') {
functionCode += `if (arrayLength && arrayLength >= ${largeArraySize}) return JSON.stringify(obj)\n`
} else {
Copy link
Contributor Author

@salesh salesh Feb 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because validLargeArrayMechanisms -> this throw will never happen (we get an early throw if largeArrayMechanism is not default or json-stringify) so no need for it -> already covered by tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats true

throw new Error(`Unsupported large array mechanism ${largeArrayMechanism}`)
}
if (largeArrayMechanism === 'json-stringify') {
functionCode += `if (arrayLength && arrayLength >= ${largeArraySize}) return JSON.stringify(obj)\n`
}

functionCode += `
Expand Down Expand Up @@ -663,8 +659,6 @@ function buildArrayTypeCondition (type, accessor) {
return buildArrayTypeCondition(subType, accessor)
})
condition = `(${conditions.join(' || ')})`
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this case is not possible because validation of types schema is invalid: data/properties/ids/type must be equal to one of the allowed values -> already covered by tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which line is already handling this already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function isValidSchema (schema, name) {
whenever i try to set something for the type that is not in that switch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concrete line

isValidSchema(options.schema[key], key)

throw new Error(`${type} unsupported`)
}
}
return condition
Expand Down
12 changes: 12 additions & 0 deletions test/integer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ test('render a float as an integer', (t) => {
}
})

test('throws on NaN', (t) => {
t.plan(1)

const schema = {
title: 'integer',
type: 'integer'
}

const stringify = build(schema)
t.throws(() => stringify(NaN), new Error('The value "NaN" cannot be converted to an integer.'))
})

test('render a float as an integer', (t) => {
const cases = [
{ input: Math.PI, output: '3' },
Expand Down