-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
Copy pathcheck-error.js
36 lines (32 loc) · 966 Bytes
/
check-error.js
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
const { CONSTANTS } = require('./constants.js');
const { SPECIAL_PROP_VALUE, CORRECT_RESULT_MSG, INCORRECT_RESULT_MSG } = CONSTANTS;
const checkForThrowingErrors = function (testsFuncs, expectedErrMsg) {
return testsFuncs.map(f => {
try {
f();
} catch (err) {
if (err._specialProp === SPECIAL_PROP_VALUE) {
this.skip();
} else if (err.message === expectedErrMsg) {
return CORRECT_RESULT_MSG;
}
}
});
};
const checkForNotThrowingErrors = function (testFuncs) {
return testFuncs.map(f => {
try {
f();
} catch (err) {
if (err._specialProp === SPECIAL_PROP_VALUE) {
this.skip();
} else {
return INCORRECT_RESULT_MSG;
}
}
});
};
module.exports = {
checkForThrowingErrors,
checkForNotThrowingErrors
};