Created
June 28, 2019 15:59
-
-
Save arnaudrenaud/e0e36c30fa640df6e58edd5de06cf289 to your computer and use it in GitHub Desktop.
Jest inline snapshots example
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
const parseDate = (year, fullDate) => { | |
if (!year) { | |
throw new Error('arg year is missing'); | |
} | |
if (!fullDate) { | |
return new Date(year); | |
} | |
return new Date(fullDate); | |
}; | |
module.exports = parseDate; |
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
const parseDate = require('./index'); | |
describe('index', () => { | |
describe('parseDate', () => { | |
describe('When no params passed', () => { | |
it('throws error', () => { | |
expect(() => parseDate()).toThrowErrorMatchingInlineSnapshot( | |
`"arg year is missing"` | |
); | |
}); | |
}); | |
describe('When passed year without fullDate', () => { | |
it('returns 01/01/year', () => { | |
expect(parseDate('1987')).toMatchInlineSnapshot( | |
`1987-01-01T00:00:00.000Z` | |
); | |
}); | |
}); | |
describe('When passed year and fullDate', () => { | |
it('returns full date', () => { | |
expect(parseDate('1987', '1987-07-12')).toMatchInlineSnapshot( | |
`1987-07-12T00:00:00.000Z` | |
); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment