Skip to content
Permalink
Browse files

Support for empty strings

  • Loading branch information
Ajaxy committed Aug 30, 2018
1 parent 18e2d5b commit 12d0b792247b011ccb7ec0bb43d7379b3638add0
Showing with 23 additions and 3 deletions.
  1. +1 −1 lib/index.js
  2. +22 −2 tests/all.test.js
@@ -12,7 +12,7 @@ function castWithSchema(query, schema) {
}

function castProp(value, propertyDef) {
if (!value || !propertyDef) {
if (!propertyDef || value === undefined) {
return value;
}

@@ -30,7 +30,11 @@ describe('All', () => {
s: ['777', '7.77', 'invalid-number'],
t: {}, // invalid array
u: 'value', // missing schema type
v: 'value', // missing type
v: 'value', // missing type,
w: '',
x: '', // `NaN` with integer
y: '', // `0` with number
z: '', // `true` with boolean
}, {
type: 'object',
properties: {
@@ -123,8 +127,20 @@ describe('All', () => {
type: 'number',
},
},
u: {
u: {},
w: {
type: 'string',
},
x: {
type: 'integer',
},
y: {
type: 'number',
},
z: {
type: 'boolean',
},

},
})).toEqual({
a: 'value',
@@ -155,6 +171,10 @@ describe('All', () => {
t: undefined,
u: 'value',
v: 'value',
w: '',
x: NaN,
y: 0,
z: true,
});
});
});

0 comments on commit 12d0b79

Please sign in to comment.
You can’t perform that action at this time.