49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
const { describe, expect, test } = require('@jest/globals');
|
|
const { parse } = require('./helpers');
|
|
|
|
describe(parse.name, () => {
|
|
const TEST_DATA = {
|
|
title: 'test',
|
|
amount: 1000,
|
|
};
|
|
|
|
[
|
|
['number title', { ...TEST_DATA, title: 11 }],
|
|
['boolean title', { ...TEST_DATA, title: false }],
|
|
['object title', { ...TEST_DATA, title: {} }],
|
|
['null title', { ...TEST_DATA, title: null }],
|
|
['boolean amount', { ...TEST_DATA, amount: true }],
|
|
['object amount', { ...TEST_DATA, amount: {} }],
|
|
].forEach(([tag, badData]) => {
|
|
test(`it rejects ${tag} as bad data`, () => {
|
|
expect(() => parse(badData)).toThrow();
|
|
});
|
|
});
|
|
test('it accepts a regular value', () => {
|
|
let result;
|
|
expect(() => {
|
|
result = parse(TEST_DATA);
|
|
}).not.toThrow();
|
|
expect(result).toEqual(TEST_DATA);
|
|
});
|
|
test('it parses yen', () => {
|
|
let result;
|
|
expect(() => {
|
|
result = parse({ title: 'test', amount: '¥3,746'});
|
|
}).not.toThrow();
|
|
expect(result).toEqual({
|
|
amount: 3746,
|
|
title: 'test',
|
|
});
|
|
});
|
|
test('it strips out non-number values from strings', () => {
|
|
let result;
|
|
expect(() => {
|
|
result = parse({ title: 'test', amount: '¥3,7~4j6.1t1'});
|
|
}).not.toThrow();
|
|
expect(result).toEqual({
|
|
amount: 374611,
|
|
title: 'test',
|
|
});
|
|
});
|
|
});
|