WeAreGenki/minna-ui

View on GitHub
utils/utils/__tests__/handle-err.test.ts

Summary

Maintainability
A
0 mins
Test Coverage
/** @jest-environment node */

import { handleErr } from '../handle-err';

describe('Nodejs error handler', () => {
  it('throws error when it exists', () => {
    expect.assertions(1);
    function wrapper(): void {
      handleErr(new Error('err'));
    }
    expect(wrapper).toThrow();
  });

  it("doesn't throw when error is missing", () => {
    expect.assertions(1);
    function wrapper(): void {
      handleErr();
    }
    expect(wrapper).not.toThrow();
  });

  it('throws on string input', () => {
    expect.assertions(1);
    function wrapper(): void {
      // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
      // @ts-ignore - Wrong type on purpose
      handleErr('just a string');
    }
    expect(wrapper).toThrow();
  });
});