aboutsummaryrefslogtreecommitdiff
path: root/src/utils/error.test.ts
blob: 027280495f2794189ac87b31114ea58b30addf3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { describe, expect, it } from 'vitest';
import { getErrorMessageIfThrows } from './error';

describe('error util', () => {
  describe('getErrorMessageIfThrows', () => {
    it('get an error message if the callback throws, undefined instead', () => {
      expect(
        getErrorMessageIfThrows(() => {
          throw 'message';
        }),
      ).to.equal('message');

      expect(
        getErrorMessageIfThrows(() => {
          throw new Error('message');
        }),
      ).to.equal('message');

      expect(
        getErrorMessageIfThrows(() => {
          throw { message: 'message' };
        }),
      ).to.equal('message');

      // eslint-disable-next-line @typescript-eslint/no-empty-function
      expect(getErrorMessageIfThrows(() => {})).to.equal(undefined);
    });
  });
});