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) {
}
Object.keys(obj).forEach((prop) => {
if (typeof obj[prop] === 'object') {
if (typeof obj[prop] === 'object' && obj[prop]) {
const convertObj = newObject[conversionFn(prop)] = {};
convert(obj[prop], conversionFn, convertObj);
} else {
......
......@@ -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', () => {
expect(util.convert({
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