forked from jmcdo29/nest-commander
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.command.factory.spec.ts
More file actions
39 lines (35 loc) · 1.29 KB
/
basic.command.factory.spec.ts
File metadata and controls
39 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { TestingModule } from '@nestjs/testing';
import { CommandTestFactory } from 'nest-commander-testing';
import { LogService } from '../src/log.service';
import { RootModule } from '../src/root.module';
import { commandMock } from './utils';
describe('Basic Command', () => {
const logMock = jest.fn();
let commandInstance: TestingModule;
const args = ['node', '/some/file.js', 'basic', 'test'];
beforeAll(async () => {
commandInstance = await CommandTestFactory.createTestingCommand({
imports: [RootModule],
})
.overrideProvider(LogService)
.useValue({ log: logMock })
.compile();
});
describe.only('flags', () => {
it.each`
flagAndVal | expected
${['--string=hello']} | ${{ string: 'hello' }}
${['-s', 'goodbye']} | ${{ string: 'goodbye' }}
${['--number=10']} | ${{ number: 10 }}
${['-n', '5']} | ${{ number: 5 }}
${['--boolean=true']} | ${{ boolean: true }}
${['-b', 'false']} | ${{ boolean: false }}
`(
'$flagAndVal \tlogs $expected',
async ({ flagAndVal, expected }: { flagAndVal: string[]; expected: Record<string, any> }) => {
await CommandTestFactory.run(commandInstance, [...args, ...flagAndVal]);
commandMock(expected, logMock);
},
);
});
});