This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for
numberWithCommas
- Loading branch information
1 parent
e476f5b
commit ee3a066
Showing
1 changed file
with
33 additions
and
0 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,33 @@ | ||
import numberWithCommas from './numberWithCommas' | ||
|
||
test('leaves single-digit values alone', () => { | ||
for (let i = 0; i <= 9; i++) { | ||
expect(numberWithCommas(i)).toEqual(`${i}`) | ||
} | ||
}) | ||
|
||
test('leaves double-digit values alone', () => { | ||
for (let i = 10; i <= 99; i++) { | ||
expect(numberWithCommas(i)).toEqual(`${i}`) | ||
} | ||
}) | ||
|
||
test('leaves triple-digit values alone', () => { | ||
for (let i = 100; i <= 999; i++) { | ||
expect(numberWithCommas(i)).toEqual(`${i}`) | ||
} | ||
}) | ||
|
||
test('inserts a grouping separator between the hundreds and thousands places', () => { | ||
expect(numberWithCommas(1000)).toEqual('1,000') | ||
expect(numberWithCommas(1234)).toEqual('1,234') | ||
expect(numberWithCommas(9999)).toEqual('9,999') | ||
expect(numberWithCommas(58763)).toEqual('58,763') | ||
}) | ||
|
||
test('inserts grouping separators at all relevant places', () => { | ||
expect(numberWithCommas(1000000000)).toEqual('1,000,000,000') | ||
expect(numberWithCommas(1234567890)).toEqual('1,234,567,890') | ||
expect(numberWithCommas(9999999999)).toEqual('9,999,999,999') | ||
expect(numberWithCommas(5876319472)).toEqual('5,876,319,472') | ||
}) |