This commit is contained in:
David Kale
2020-09-08 13:25:36 -04:00
parent e4246d2b5b
commit 91fcbb0108
4227 changed files with 416837 additions and 457884 deletions

View File

@@ -61,27 +61,30 @@ const operatorMessage = operator => {
};
const assertThrowingMatcherHint = operatorName =>
_chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('function') +
_chalk.default.dim(')');
operatorName
? _chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('function') +
_chalk.default.dim(')')
: '';
const assertMatcherHint = (operator, operatorName) => {
let message =
_chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('received') +
_chalk.default.dim(', ') +
_chalk.default.green('expected') +
_chalk.default.dim(')');
const assertMatcherHint = (operator, operatorName, expected) => {
let message = '';
if (operator === '==') {
message +=
' or ' +
if (operator === '==' && expected === true) {
message =
_chalk.default.dim('assert') +
_chalk.default.dim('(') +
_chalk.default.red('received') +
_chalk.default.dim(') ');
_chalk.default.dim(')');
} else if (operatorName) {
message =
_chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('received') +
_chalk.default.dim(', ') +
_chalk.default.green('expected') +
_chalk.default.dim(')');
}
return message;
@@ -103,8 +106,7 @@ function assertionErrorMessage(error, options) {
if (operatorName === 'doesNotThrow') {
return (
assertThrowingMatcherHint(operatorName) +
'\n\n' +
buildHintString(assertThrowingMatcherHint(operatorName)) +
_chalk.default.reset(`Expected the function not to throw an error.\n`) +
_chalk.default.reset(`Instead, it threw:\n`) +
` ${(0, _jestMatcherUtils.printReceived)(actual)}` +
@@ -117,8 +119,7 @@ function assertionErrorMessage(error, options) {
if (operatorName === 'throws') {
return (
assertThrowingMatcherHint(operatorName) +
'\n\n' +
buildHintString(assertThrowingMatcherHint(operatorName)) +
_chalk.default.reset(`Expected the function to throw an error.\n`) +
_chalk.default.reset(`But it didn't throw anything.`) +
_chalk.default.reset(
@@ -129,8 +130,7 @@ function assertionErrorMessage(error, options) {
}
return (
assertMatcherHint(operator, operatorName) +
'\n\n' +
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
_chalk.default.reset(`Expected value ${operatorMessage(operator)}`) +
` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +
_chalk.default.reset(`Received:\n`) +
@@ -141,5 +141,9 @@ function assertionErrorMessage(error, options) {
);
}
function buildHintString(hint) {
return hint ? hint + '\n\n' : '';
}
var _default = assertionErrorMessage;
exports.default = _default;