-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4082 from marmelab/Fix-form-breaks-when-setting-c…
…omplex-value Fix Form breaks when setting undefined value to object
- Loading branch information
Showing
2 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import expect from 'expect'; | ||
import sanitizeEmptyValues from './sanitizeEmptyValues'; | ||
|
||
describe('sanitizeEmptyValues', () => { | ||
it('should set null or undefined values to null', () => { | ||
expect(sanitizeEmptyValues({ foo: 23 }, {})).toEqual({ foo: null }); | ||
expect(sanitizeEmptyValues({ foo: 'hello' }, {})).toEqual({ | ||
foo: null, | ||
}); | ||
expect(sanitizeEmptyValues({ foo: new Date() }, {})).toEqual({ | ||
foo: null, | ||
}); | ||
expect(sanitizeEmptyValues({ foo: { bar: 2 } }, {})).toEqual({ | ||
foo: null, | ||
}); | ||
}); | ||
it('should set null or undefined deep values to null', () => { | ||
expect(sanitizeEmptyValues({ foo: { bar: 1 } }, { foo: {} })).toEqual({ | ||
foo: { bar: null }, | ||
}); | ||
}); | ||
it('should accept string values', () => { | ||
const str = 'hello'; | ||
expect(sanitizeEmptyValues({ str: null }, { str })).toEqual({ str }); | ||
expect(sanitizeEmptyValues({}, { str })).toEqual({ str }); | ||
}); | ||
it('should accept date values', () => { | ||
const date = new Date(); | ||
expect(sanitizeEmptyValues({ date: null }, { date })).toEqual({ date }); | ||
expect(sanitizeEmptyValues({}, { date })).toEqual({ date }); | ||
}); | ||
it('should accept array values', () => { | ||
const arr = [1, 2, 3]; | ||
expect(sanitizeEmptyValues({ arr: null }, { arr })).toEqual({ arr }); | ||
expect(sanitizeEmptyValues({}, { arr })).toEqual({ arr }); | ||
}); | ||
it('should accept object values', () => { | ||
const obj = { foo: 1 }; | ||
expect(sanitizeEmptyValues({ obj: null }, { obj })).toEqual({ obj }); | ||
expect(sanitizeEmptyValues({}, { obj })).toEqual({ obj }); | ||
}); | ||
it('should accept deep object values', () => { | ||
const obj = { foo: { bar: 1 } }; | ||
expect( | ||
sanitizeEmptyValues({ obj: { foo: null, foo2: 2 } }, { obj }) | ||
).toEqual({ obj: { foo: { bar: 1 }, foo2: null } }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters