Commit 6b6b80d8 authored by Aaron Tidwell's avatar Aaron Tidwell Committed by GitHub

fix null values becoming empty objects (#26)

parent 63bb26f1
...@@ -46,7 +46,7 @@ function convert(obj, conversionFn, newObject) { ...@@ -46,7 +46,7 @@ function convert(obj, conversionFn, newObject) {
} }
Object.keys(obj).forEach((prop) => { Object.keys(obj).forEach((prop) => {
if (typeof obj[prop] === 'object') { if (typeof obj[prop] === 'object' && obj[prop]) {
const convertObj = newObject[conversionFn(prop)] = {}; const convertObj = newObject[conversionFn(prop)] = {};
convert(obj[prop], conversionFn, convertObj); convert(obj[prop], conversionFn, convertObj);
} else { } else {
......
...@@ -140,6 +140,18 @@ describe('util methods', () => { ...@@ -140,6 +140,18 @@ describe('util methods', () => {
}); });
}); });
it('should work with a null value', () => {
expect(util.convert({
top_prop: {
middle_prop: null
}
}, util.underscoreToCamel)).toEqual({
topProp: {
middleProp: null
}
});
});
it('should work with both top and nested properties', () => { it('should work with both top and nested properties', () => {
expect(util.convert({ expect(util.convert({
top_prop: { top_prop: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment