Skip to content

Commit

Permalink
Fix typo in unit test description (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 24, 2021
1 parent 63886a9 commit 256e1c6
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
import createD3NumberFormatter from '../../src/factories/createD3NumberFormatter';

describe('D3NumberFormatter', () => {
describe('new D3NumberFormatter(config)', () => {
it('requires config.formatString', () => {
expect(() => createD3NumberFormatter()).toThrow();
describe('createD3NumberFormatter(config)', () => {
it('requires config.formatString', () => {
expect(() => createD3NumberFormatter()).toThrow();
});
describe('config.formatString', () => {
it('creates a NumberFormatter with the formatString as id', () => {
const formatter = createD3NumberFormatter({ formatString: '.2f' });
expect(formatter.id).toEqual('.2f');
});
describe('config.formatString', () => {
it('creates a NumberFormatter with the formatString as id', () => {
describe('if it is valid d3 formatString', () => {
it('uses d3.format(config.formatString) as format function', () => {
const formatter = createD3NumberFormatter({ formatString: '.2f' });
expect(formatter.id).toEqual('.2f');
expect(formatter.format(100)).toEqual('100.00');
});
describe('if it is valid d3 formatString', () => {
it('uses d3.format(config.formatString) as format function', () => {
const formatter = createD3NumberFormatter({ formatString: '.2f' });
expect(formatter.format(100)).toEqual('100.00');
});
});
describe('if it is invalid d3 formatString', () => {
it('The format function displays error message', () => {
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' });
expect(formatter.format(12345.67)).toEqual('12345.67 (Invalid format: i-am-groot)');
});
describe('if it is invalid d3 formatString', () => {
it('The format function displays error message', () => {
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' });
expect(formatter.format(12345.67)).toEqual('12345.67 (Invalid format: i-am-groot)');
});
it('also set formatter.isInvalid to true', () => {
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' });
expect(formatter.isInvalid).toEqual(true);
});
it('also set formatter.isInvalid to true', () => {
const formatter = createD3NumberFormatter({ formatString: 'i-am-groot' });
expect(formatter.isInvalid).toEqual(true);
});
});
describe('config.label', () => {
it('set label if specified', () => {
const formatter = createD3NumberFormatter({
formatString: '.2f',
label: 'float formatter',
});
expect(formatter.label).toEqual('float formatter');
});
describe('config.label', () => {
it('set label if specified', () => {
const formatter = createD3NumberFormatter({
formatString: '.2f',
label: 'float formatter',
});
expect(formatter.label).toEqual('float formatter');
});
describe('config.description', () => {
it('set decription if specified', () => {
const formatter = createD3NumberFormatter({
description: 'lorem ipsum',
formatString: '.2f',
});
expect(formatter.description).toEqual('lorem ipsum');
});
describe('config.description', () => {
it('set decription if specified', () => {
const formatter = createD3NumberFormatter({
description: 'lorem ipsum',
formatString: '.2f',
});
expect(formatter.description).toEqual('lorem ipsum');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
import NumberFormatter from '../../src/NumberFormatter';
import createSiAtMostNDigitFormatter from '../../src/factories/createSiAtMostNDigitFormatter';

describe('SiAtMostNDigitFormatter', () => {
describe('new SiAtMostNDigitFormatter(n)', () => {
it('creates an instance of NumberFormatter', () => {
const formatter = createSiAtMostNDigitFormatter({ n: 4 });
expect(formatter).toBeInstanceOf(NumberFormatter);
});
it('when n is specified, it formats number in SI format with at most n significant digits', () => {
const formatter = createSiAtMostNDigitFormatter({ n: 2 });
expect(formatter(10)).toBe('10');
expect(formatter(1)).toBe('1');
expect(formatter(1.0)).toBe('1');
expect(formatter(10.0)).toBe('10');
expect(formatter(10001)).toBe('10k');
expect(formatter(10100)).toBe('10k');
expect(formatter(111000000)).toBe('110M');
expect(formatter(0.23)).toBe('230m');
expect(formatter(0)).toBe('0');
expect(formatter(-10)).toBe('-10');
expect(formatter(-1)).toBe('-1');
expect(formatter(-1.0)).toBe('-1');
expect(formatter(-10.0)).toBe('-10');
expect(formatter(-10001)).toBe('-10k');
expect(formatter(-10101)).toBe('-10k');
expect(formatter(-111000000)).toBe('-110M');
expect(formatter(-0.23)).toBe('-230m');
});
it('when n is not specified, it defaults to n=3', () => {
const formatter = createSiAtMostNDigitFormatter();
expect(formatter(10)).toBe('10');
expect(formatter(1)).toBe('1');
expect(formatter(1.0)).toBe('1');
expect(formatter(10.0)).toBe('10');
expect(formatter(10001)).toBe('10.0k');
expect(formatter(10100)).toBe('10.1k');
expect(formatter(111000000)).toBe('111M');
expect(formatter(0.23)).toBe('230m');
expect(formatter(0)).toBe('0');
expect(formatter(-10)).toBe('-10');
expect(formatter(-1)).toBe('-1');
expect(formatter(-1.0)).toBe('-1');
expect(formatter(-10.0)).toBe('-10');
expect(formatter(-10001)).toBe('-10.0k');
expect(formatter(-10101)).toBe('-10.1k');
expect(formatter(-111000000)).toBe('-111M');
expect(formatter(-0.23)).toBe('-230m');
});
describe('createSiAtMostNDigitFormatter({ n })', () => {
it('creates an instance of NumberFormatter', () => {
const formatter = createSiAtMostNDigitFormatter({ n: 4 });
expect(formatter).toBeInstanceOf(NumberFormatter);
});
it('when n is specified, it formats number in SI format with at most n significant digits', () => {
const formatter = createSiAtMostNDigitFormatter({ n: 2 });
expect(formatter(10)).toBe('10');
expect(formatter(1)).toBe('1');
expect(formatter(1.0)).toBe('1');
expect(formatter(10.0)).toBe('10');
expect(formatter(10001)).toBe('10k');
expect(formatter(10100)).toBe('10k');
expect(formatter(111000000)).toBe('110M');
expect(formatter(0.23)).toBe('230m');
expect(formatter(0)).toBe('0');
expect(formatter(-10)).toBe('-10');
expect(formatter(-1)).toBe('-1');
expect(formatter(-1.0)).toBe('-1');
expect(formatter(-10.0)).toBe('-10');
expect(formatter(-10001)).toBe('-10k');
expect(formatter(-10101)).toBe('-10k');
expect(formatter(-111000000)).toBe('-110M');
expect(formatter(-0.23)).toBe('-230m');
});
it('when n is not specified, it defaults to n=3', () => {
const formatter = createSiAtMostNDigitFormatter();
expect(formatter(10)).toBe('10');
expect(formatter(1)).toBe('1');
expect(formatter(1.0)).toBe('1');
expect(formatter(10.0)).toBe('10');
expect(formatter(10001)).toBe('10.0k');
expect(formatter(10100)).toBe('10.1k');
expect(formatter(111000000)).toBe('111M');
expect(formatter(0.23)).toBe('230m');
expect(formatter(0)).toBe('0');
expect(formatter(-10)).toBe('-10');
expect(formatter(-1)).toBe('-1');
expect(formatter(-1.0)).toBe('-1');
expect(formatter(-10.0)).toBe('-10');
expect(formatter(-10001)).toBe('-10.0k');
expect(formatter(-10101)).toBe('-10.1k');
expect(formatter(-111000000)).toBe('-111M');
expect(formatter(-0.23)).toBe('-230m');
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createMultiFormatter from '../../src/factories/createMultiFormatter';

describe('createMultiFormatter', () => {
describe('createMultiFormatter()', () => {
describe('creates a multi-step formatter', () => {
const formatter = createMultiFormatter({
id: 'my_format',
Expand Down

0 comments on commit 256e1c6

Please sign in to comment.