Skip to content

Commit

Permalink
test(core): fix scenario on external exceptions handler
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Oct 29, 2022
1 parent 8af21d1 commit 1d8c56a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/core/test/exceptions/external-exceptions-handler.spec.ts
Expand Up @@ -2,22 +2,23 @@ import { expect } from 'chai';
import { of } from 'rxjs';
import * as sinon from 'sinon';
import { ExternalExceptionsHandler } from '../../exceptions/external-exceptions-handler';
import { ExternalExceptionFilter } from '../../exceptions/external-exception-filter';

describe('ExternalExceptionsHandler', () => {
let handler: ExternalExceptionsHandler;

beforeEach(() => {
handler = new ExternalExceptionsHandler();

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore The 'logger' property is private but we want to avoid showing useless error logs
ExternalExceptionFilter.logger.error = () => {};
});

describe('next', () => {
it('should method returns expected stream with message when exception is unknown', async () => {
it('should method returns expected stream with message when exception is unknown', () => {
const error = new Error();
try {
await handler.next(error, null);
} catch (err) {
expect(err).to.be.eql(error);
}
expect(() => handler.next(error, null)).to.throw(error);
});
describe('when "invokeCustomFilters" returns value', () => {
const observable$ = of(true);
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('ExternalExceptionsHandler', () => {
describe('when filters array is not empty', () => {
let filters, funcSpy;
class TestException {}
class AnotherTestException {}

beforeEach(() => {
funcSpy = sinon.spy();
Expand All @@ -73,6 +75,12 @@ describe('ExternalExceptionsHandler', () => {
});
});
describe('when filter does not exists in filters array', () => {
beforeEach(() => {
filters = [
{ exceptionMetatypes: [AnotherTestException], func: funcSpy },
];
(handler as any).filters = filters;
});
it('should not call funcSpy', () => {
handler.invokeCustomFilters(new TestException(), null);
expect(funcSpy.notCalled).to.be.true;
Expand Down

0 comments on commit 1d8c56a

Please sign in to comment.