Set up a test for the failing parsing

This commit is contained in:
Campbell Alden 2026-03-25 19:19:03 +09:00
parent 4e4760b55a
commit f2112c360d
5 changed files with 4354 additions and 35 deletions

49
helpers.spec.js Normal file
View file

@ -0,0 +1,49 @@
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',
});
});
});