Skip to content

Commit

Permalink
test(error): add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilschumacher committed Jun 4, 2021
1 parent da90a6b commit 276a8a3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as chai from "chai";
import * as sinon from "sinon";

import { onUncaughtException, onUnhandledRejection } from "../src/error";

describe("error", () => {
let sandbox: sinon.SinonSandbox;

beforeEach(() => (sandbox = sinon.createSandbox()));
afterEach(() => sandbox.restore());

it("should print an error for an exception", () => {
// Given
const consoleErrorStub = sandbox.stub(console, "error");
const processExitStub = sandbox.stub(process, "exit");

const error = new SyntaxError(
"Invalid regular expression: /^(feat)(((?scope>.*)))?(?<breaking>!)?: (?<description>.*)/: Invalid group",
);

// When
onUncaughtException(error);

// Then
chai.expect(consoleErrorStub).to.have.been.calledWith(
"An unknown error occurred. Failed to generate Markdown report.",
);
chai.expect(processExitStub).to.have.been.calledWith(1);
});

it("should print an error for a unhandled rejection", () => {
// Given
const consoleErrorStub = sandbox.stub(console, "error");
const processExitStub = sandbox.stub(process, "exit");

const error = new SyntaxError(
"Invalid regular expression: /^(feat)(((?scope>.*)))?(?<breaking>!)?: (?<description>.*)/: Invalid group",
);
const promise = Promise.reject();

// When
onUnhandledRejection(error, promise);

// Then
chai.expect(consoleErrorStub).to.have.been.calledWith(
"An unknown error occurred. Failed to generate Markdown report.",
);
chai.expect(processExitStub).to.have.been.calledWith(1);
});
});

0 comments on commit 276a8a3

Please sign in to comment.