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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
import { parseErrorMessage, USER_FACING_ERROR_MESSAGE_PREFIX } from '~/lib/utils/error_message';
const defaultErrorMessage = 'Something caused this error';
const userFacingErrorMessage = 'User facing error message';
const nonUserFacingErrorMessage = 'NonUser facing error message';
const genericErrorMessage = 'Some error message';
describe('error message', () => {
describe('when given an errormessage object', () => {
const errorMessageObject = {
options: {
cause: defaultErrorMessage,
},
filename: 'error.js',
linenumber: 7,
};
it('returns the correct values for userfacing errors', () => {
const userFacingObject = errorMessageObject;
userFacingObject.message = `${USER_FACING_ERROR_MESSAGE_PREFIX} ${userFacingErrorMessage}`;
expect(parseErrorMessage(userFacingObject)).toEqual({
message: userFacingErrorMessage,
userFacing: true,
});
});
it('returns the correct values for non userfacing errors', () => {
const nonUserFacingObject = errorMessageObject;
nonUserFacingObject.message = nonUserFacingErrorMessage;
expect(parseErrorMessage(nonUserFacingObject)).toEqual({
message: nonUserFacingErrorMessage,
userFacing: false,
});
});
});
describe('when given an errormessage string', () => {
it('returns the correct values for userfacing errors', () => {
expect(
parseErrorMessage(`${USER_FACING_ERROR_MESSAGE_PREFIX} ${genericErrorMessage}`),
).toEqual({
message: genericErrorMessage,
userFacing: true,
});
});
it('returns the correct values for non userfacing errors', () => {
expect(parseErrorMessage(genericErrorMessage)).toEqual({
message: genericErrorMessage,
userFacing: false,
});
});
});
describe('when given nothing', () => {
it('returns an empty error message', () => {
expect(parseErrorMessage()).toEqual({
message: '',
userFacing: false,
});
});
});
});
|