Skip to content

Commit 9a1e5aa

Browse files
committed
The bin should use argArray and set useless runtime and script parameters for calling main
1 parent c27b92a commit 9a1e5aa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/bin/typescript-demo-lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function main(argv = process.argv): number {
2020
process.stdout.write(uuidv4() + '\n');
2121

2222
// Add the first two command-line args and print the result
23-
const nums = new NumPair(parseInt(argv[2]), parseInt(argv[3]));
23+
const nums = new NumPair(parseInt(argArray[0]), parseInt(argArray[1]));
2424
const sum = nums.num1 + nums.num2;
2525
process.stdout.write(nums.num1 + ' + ' + nums.num2 + ' = ' + sum + '\n');
2626

tests/bin/typescript-demo-lib.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ describe('main', () => {
99
test('main takes synthetic parameters', () => {
1010
// jest can also "spy on" the console object
1111
// and then you can test on stdout
12-
expect(main(['1'])).toEqual(0);
12+
expect(main(['', '', '1', '2'])).toEqual(0);
1313
});
1414
test('no input', () => {
1515
const mockLog = mockProcessStdout();
16-
main(['thing', 'thing']);
16+
main(['', '']);
1717
expect(mockLog).toHaveBeenCalledTimes(4);
1818
expect(mockLog.mock.calls[0][0]).toBe('[]\n');
1919
expect(mockLog.mock.calls[1][0]).toBe('new library\n');
@@ -23,7 +23,7 @@ describe('main', () => {
2323
});
2424
test('adds 0 + 0', () => {
2525
const mockLog = mockProcessStdout();
26-
main(['thing', 'thing', '0', '0']);
26+
main(['', '', '0', '0']);
2727
expect(mockLog).toHaveBeenCalledTimes(4);
2828
expect(mockLog.mock.calls[0][0]).toBe('[0,0]\n');
2929
expect(mockLog.mock.calls[1][0]).toBe('new library\n');
@@ -33,7 +33,7 @@ describe('main', () => {
3333
});
3434
test('adds 0 + 1', () => {
3535
const mockLog = mockProcessStdout();
36-
main(['thing', 'thing', '0', '1']);
36+
main(['', '', '0', '1']);
3737
expect(mockLog).toHaveBeenCalledTimes(4);
3838
expect(mockLog.mock.calls[0][0]).toBe('[0,1]\n');
3939
expect(mockLog.mock.calls[1][0]).toBe('new library\n');
@@ -43,7 +43,7 @@ describe('main', () => {
4343
});
4444
test('adds 1 + 0', () => {
4545
const mockLog = mockProcessStdout();
46-
main(['thing', 'thing', '1', '0']);
46+
main(['', '', '1', '0']);
4747
expect(mockLog).toHaveBeenCalledTimes(4);
4848
expect(mockLog.mock.calls[0][0]).toBe('[1,0]\n');
4949
expect(mockLog.mock.calls[1][0]).toBe('new library\n');
@@ -53,7 +53,7 @@ describe('main', () => {
5353
});
5454
test('adds 7657 + 238947', () => {
5555
const mockLog = mockProcessStdout();
56-
main(['thing', 'thing', '7657', '238947']);
56+
main(['', '', '7657', '238947']);
5757
expect(mockLog).toHaveBeenCalledTimes(4);
5858
expect(mockLog.mock.calls[0][0]).toBe('[7657,238947]\n');
5959
expect(mockLog.mock.calls[1][0]).toBe('new library\n');

0 commit comments

Comments
 (0)