-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
basic.command.factory.spec.ts
63 lines (59 loc) · 1.63 KB
/
basic.command.factory.spec.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { TestingModule } from '@nestjs/testing';
import { CommandTestFactory } from 'nest-commander-testing';
import { spy, Stub } from 'hanbi';
import { suite } from 'uvu';
import { equal } from 'uvu/assert';
import { LogService } from '../../common/log.service';
import { RootModule } from '../src/root.module';
export const BasicFactorySuite = suite<{
commandInstance: TestingModule;
logMock: Stub<Console['log']>;
args: string[];
}>('Basic Command With Factory');
BasicFactorySuite.before(async (context) => {
context.logMock = spy();
context.args = ['basic', 'test'];
context.commandInstance = await CommandTestFactory.createTestingCommand({
imports: [RootModule],
})
.overrideProvider(LogService)
.useValue({ log: context.logMock.handler })
.compile();
});
BasicFactorySuite.after.each(({ logMock }) => {
logMock.reset();
});
for (const { flagAndVal, expected } of [
{
flagAndVal: ['--string=hello'],
expected: { string: 'hello' },
},
{
flagAndVal: ['-s', 'goodbye'],
expected: { string: 'goodbye' },
},
{
flagAndVal: ['--number=10'],
expected: { number: 10 },
},
{
flagAndVal: ['-n', '5'],
expected: { number: 5 },
},
{
flagAndVal: ['--boolean=true'],
expected: { boolean: true },
},
{
flagAndVal: ['-b', 'false'],
expected: { boolean: false },
},
]) {
BasicFactorySuite(
`${flagAndVal} \tlogs ${JSON.stringify(expected)}`,
async ({ commandInstance, logMock, args }) => {
await CommandTestFactory.run(commandInstance, [...args, ...flagAndVal]);
equal(logMock.firstCall?.args[0], { param: ['test'], ...expected });
},
);
}