Replies: 1 comment
-
FYI, I was able to patch in a mock for describe('AwsProfilesCommand', () => {
let command: AwsProfilesCommand;
let cr_mock: any;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AwsProfilesCommand],
}).compile();
command = module.get<AwsProfilesCommand>(AwsProfilesCommand);
cr_mock = (command as any).command = createMock<CommandRunner>();
jest.resetAllMocks();
});
it('should throw an error', async () => {
await command.run([]);
expect(cr_mock.error).toHaveBeenLastCalledWith(
'File XXXXXX does not exist, run login or setup first',
);
}); Not sure if this is really a good solution, happy for other - better - ideas. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a Command that has somewhere an exit condition like this:
which works very well as intended. My problem is that I cannot write a Jest unit test for the error situations. When I do then the tes fails like this:
It seems like
this.command
is not defined under test. I define my unit test the following way:I know that this is not the
nest-commander-testing
way of doing things, which doesn't work well for me because of all the other dependencies in my CLI application. My goal is to test just the one command with minimal mocking of dependencies.Beta Was this translation helpful? Give feedback.
All reactions