Browse Source

Use Jest mock functions

new-arch
David Ludwig 4 years ago
parent
commit
2d46925f0f
2 changed files with 7 additions and 10 deletions
  1. +1
    -1
      packages/microservice/package.json
  2. +6
    -9
      packages/microservice/test/integration/internal-services.test.ts

+ 1
- 1
packages/microservice/package.json View File

@ -1,6 +1,6 @@
{
"name": "@autoplex/microservice",
"version": "0.0.0",
"version": "0.1.0",
"main": "dist/lib/index.js",
"types": "dist/typings/index.d.ts",
"license": "MIT",


+ 6
- 9
packages/microservice/test/integration/internal-services.test.ts View File

@ -2,12 +2,9 @@ import { ExitCode, InternalService, Microservice, MicroserviceState } from "../.
class MockService<M extends Microservice> extends InternalService<M> {
public NAME = "Mock Service";
public hasBooted = false;
public hasStarted = false;
public hasShutdown = false;
public override async boot() { this.hasBooted = true; }
public override async start() { this.hasStarted = true; }
public override async shutdown() { this.hasShutdown = true; }
public override boot = jest.fn();
public override start = jest.fn();
public override shutdown = jest.fn();
}
class MockServiceBootFail<M extends Microservice> extends InternalService<M> {
@ -38,9 +35,9 @@ describe("Microservice/Internal Service Integration", () => {
let executing = microservice.exec();
microservice.on("ready", () => microservice.quit());
await executing;
expect(microservice.service(MockService).hasBooted).toBe(true);
expect(microservice.service(MockService).hasStarted).toBe(true);
expect(microservice.service(MockService).hasShutdown).toBe(true);
expect(microservice.service(MockService).boot).toHaveBeenCalled();
expect(microservice.service(MockService).start).toHaveBeenCalled();
expect(microservice.service(MockService).shutdown).toHaveBeenCalled();
});
test("Trigger boot failure", async () => {
let microservice = new Microservice();


Loading…
Cancel
Save