Created
October 20, 2017 03:54
-
-
Save wldcordeiro/2cdd00730896736d387b15e50a08eb42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// I believe this is doable thanks to the transform-object-rest-spread Babel plugin. | |
export function formatConditionalAnimals({ bears, cats }) { | |
return { | |
animals: { | |
...(bears != null && { bears }), | |
...(cats != null && { cats }), | |
}, | |
} | |
} | |
describe('formatConditionalAnimals', () => { | |
it('formats the bears only', () => { | |
const testBears = 3 | |
expect(formatConditionalAnimals({ bears: testBears })).toMatchSnapshot() | |
}) | |
it('formats the bears and cats', () => { | |
const testBears = 3 | |
const testCats = 100 | |
expect( | |
formatConditionalAnimals({ | |
bears: testBears, | |
cats: testCats, | |
}) | |
).toMatchSnapshot() | |
}) | |
}) |
This file contains hidden or 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
// Jest Snapshot v1, https://goo.gl/fbAQLP | |
exports[`formatConditionalAnimals formats the bears and cats 1`] = ` | |
Object { | |
"animals": Object { | |
"bears": 3, | |
"cats": 100, | |
}, | |
} | |
`; | |
exports[`formatConditionalAnimals formats the bears only 1`] = ` | |
Object { | |
"animals": Object { | |
"bears": 3, | |
}, | |
} | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment