]> src.bluestatic.org Git - ustaxlib.git/blob - src/Form.test.ts
Add Line.test.ts.
[ustaxlib.git] / src / Form.test.ts
1 import { ComputedLine, Line } from './Line';
2 import TaxReturn from './TaxReturn';
3 import Form from './Form';
4 import { InconsistencyError, NotFoundError } from './Errors';
5
6 test('add and get line', () => {
7 const l = new ComputedLine<number>('1', () => 42);
8
9 class TestForm extends Form {
10 get name(): string {
11 return 'Test Form';
12 }
13
14 protected getLines() {
15 return [l];
16 }
17 };
18
19 const f = new TestForm();
20 expect(f.getLine('1')).toBe(l);
21 });
22
23 test('get non-existent line', () => {
24 class TestForm extends Form {
25 get name(): string {
26 return 'Test Form';
27 }
28
29 protected getLines() {
30 return [];
31 }
32 };
33
34 const f = new TestForm();
35 expect(() => f.getLine('1')).toThrow(NotFoundError);
36 });
37
38 test('add duplicate line', () => {
39 const l1 = new ComputedLine<number>('1', () => 42);
40 const l2 = new ComputedLine<number>('1', () => 36);
41
42 class TestForm extends Form {
43 get name(): string {
44 return 'Test Form';
45 }
46
47 protected getLines() {
48 return [l1, l2];
49 }
50 };
51
52 expect(() => new TestForm()).toThrow(InconsistencyError);
53 });