-
Hey! I would like to write some e2e tests and check the expected result like a response body. Is it possible? Example: import { TestingModule } from "@nestjs/testing";
import { CommandTestFactory } from "nest-commander-testing";
import { AppModule } from "../../../src/app.module";
describe("Health Check Cronjob (e2e)", () => {
let commandInstance: TestingModule;
beforeAll(async () => {
commandInstance = await CommandTestFactory.createTestingCommand({
imports: [AppModule],
}).compile();
});
it("Should run successful", async () => {
const result = await CommandTestFactory.run(commandInstance, [
"health-check-cronjob",
]);
expect(result.status).toBe("ok");
});
afterAll(async () => {
await commandInstance.close();
});
});
Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Currently, there isn't a way to return the result of the command, mainly due to the fact that when running the command there's no return to anything, usually only outcomes like writing a log to the terminal, making changes to a database, or calling an API. I could probably write up a way to get the |
Beta Was this translation helpful? Give feedback.
Currently, there isn't a way to return the result of the command, mainly due to the fact that when running the command there's no return to anything, usually only outcomes like writing a log to the terminal, making changes to a database, or calling an API.
I could probably write up a way to get the
CommandTestFactory.run()
to return whatever the result of whatever command ran, to help with testing, but you'd almost be better off spying on the command and itsrun
method and asserting what the spy responds with.