Skip to content

Instantly share code, notes, and snippets.

@anthanh
Created April 21, 2020 22:06
Show Gist options
  • Save anthanh/86d220afa05bca16fca7ad4ee535c1ee to your computer and use it in GitHub Desktop.
Save anthanh/86d220afa05bca16fca7ad4ee535c1ee to your computer and use it in GitHub Desktop.
describe('formatNumber function', () => {
it('works with strings', () => {
const formatted = formatNumber('12.45')
expect(formatted).toEqual('12,45')
})
it('works with numbers', () => {
const formatted = formatNumber(12.45)
expect(formatted).toEqual('12,45')
})
it('returns only 2 decimal places', () => {
const formatted = formatNumber(12.1111)
expect(formatted).toEqual('12,11')
})
it('rounds decimals right', () => {
expect(formatNumber(12.665)).toEqual('12,67')
expect(formatNumber(12.664)).toEqual('12,66')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment