2018-08-09 18:50:56 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { numberFormat } from '../index';
|
|
|
|
|
|
|
|
describe( 'numberFormat', () => {
|
2019-01-17 01:40:45 +00:00
|
|
|
it( 'should default to precision=null decimal=. thousands=,', () => {
|
|
|
|
expect( numberFormat( 1000 ) ).toBe( '1,000' );
|
2018-08-09 18:50:56 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should return an empty string if no argument is passed', () => {
|
|
|
|
expect( numberFormat() ).toBe( '' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should accept a string', () => {
|
2019-01-17 01:40:45 +00:00
|
|
|
expect( numberFormat( '10000' ) ).toBe( '10,000' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'maintains all decimals if no precision specified', () => {
|
|
|
|
expect( numberFormat( '10000.123456' ) ).toBe( '10,000.123456' );
|
2019-01-17 00:32:12 +00:00
|
|
|
} );
|
|
|
|
|
2019-01-17 23:28:00 +00:00
|
|
|
it( 'maintains all decimals if invalid precision specified', () => {
|
|
|
|
expect( numberFormat( '10000.123456', 'not a number' ) ).toBe( '10,000.123456' );
|
|
|
|
} );
|
|
|
|
|
2019-01-17 00:32:12 +00:00
|
|
|
it( 'uses store currency settings, not locale', () => {
|
|
|
|
global.wcSettings.siteLocale = 'en-US';
|
|
|
|
global.wcSettings.currency.decimal_separator = ',';
|
|
|
|
global.wcSettings.currency.thousand_separator = '.';
|
|
|
|
|
2019-01-17 01:40:45 +00:00
|
|
|
expect( numberFormat( '12345.6789', 3 ) ).toBe( '12.345,679' );
|
2018-08-09 18:50:56 +00:00
|
|
|
} );
|
|
|
|
} );
|