jest-matcher-utils
Advanced tools
Comparing version 22.4.0 to 23.0.0-alpha.0
@@ -1,56 +0,51 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.matcherHint = exports.pluralize = exports.ensureNumbers = exports.ensureExpectedIsNumber = exports.ensureActualIsNumber = exports.ensureNoExpected = exports.printWithType = exports.printExpected = exports.printReceived = exports.highlightTrailingWhitespace = exports.stringify = exports.SUGGEST_TO_EQUAL = exports.RECEIVED_COLOR = exports.EXPECTED_COLOR = undefined; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.matcherHint = exports.pluralize = exports.ensureNumbers = exports.ensureExpectedIsNumber = exports.ensureActualIsNumber = exports.ensureNoExpected = exports.printWithType = exports.printExpected = exports.printReceived = exports.highlightTrailingWhitespace = exports.stringify = exports.SUGGEST_TO_EQUAL = exports.RECEIVED_COLOR = exports.EXPECTED_COLOR = undefined; | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _jestGetType = require('jest-get-type'); | ||
var _jestGetType2 = _interopRequireDefault(_jestGetType); | ||
var _prettyFormat = require('pretty-format'); | ||
var _prettyFormat2 = _interopRequireDefault(_prettyFormat); | ||
var _chalk = require('chalk');var _chalk2 = _interopRequireDefault(_chalk); | ||
var _jestGetType = require('jest-get-type');var _jestGetType2 = _interopRequireDefault(_jestGetType); | ||
var _prettyFormat = require('pretty-format');var _prettyFormat2 = _interopRequireDefault(_prettyFormat);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var _prettyFormat$plugins = | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _prettyFormat$plugins = _prettyFormat2.default.plugins; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
const AsymmetricMatcher = _prettyFormat$plugins.AsymmetricMatcher, | ||
DOMCollection = _prettyFormat$plugins.DOMCollection, | ||
DOMElement = _prettyFormat$plugins.DOMElement, | ||
Immutable = _prettyFormat$plugins.Immutable, | ||
ReactElement = _prettyFormat$plugins.ReactElement, | ||
ReactTestComponent = _prettyFormat$plugins.ReactTestComponent; | ||
const PLUGINS = [ReactTestComponent, ReactElement, DOMElement, DOMCollection, Immutable, AsymmetricMatcher]; | ||
_prettyFormat2.default.plugins; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/const AsymmetricMatcher = _prettyFormat$plugins.AsymmetricMatcher,DOMCollection = _prettyFormat$plugins.DOMCollection,DOMElement = _prettyFormat$plugins.DOMElement,Immutable = _prettyFormat$plugins.Immutable,ReactElement = _prettyFormat$plugins.ReactElement,ReactTestComponent = _prettyFormat$plugins.ReactTestComponent;const PLUGINS = [ReactTestComponent, ReactElement, DOMElement, DOMCollection, Immutable, | ||
AsymmetricMatcher]; | ||
const EXPECTED_COLOR = exports.EXPECTED_COLOR = _chalk2.default.green; | ||
const RECEIVED_COLOR = exports.RECEIVED_COLOR = _chalk2.default.red; | ||
const NUMBERS = [ | ||
'zero', | ||
'one', | ||
'two', | ||
'three', | ||
'four', | ||
'five', | ||
'six', | ||
'seven', | ||
'eight', | ||
'nine', | ||
'ten', | ||
'eleven', | ||
'twelve', | ||
'thirteen']; | ||
const NUMBERS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen']; | ||
const SUGGEST_TO_EQUAL = exports.SUGGEST_TO_EQUAL = _chalk2.default.dim('Looks like you wanted to test for object/array equality with strict `toBe` matcher. You probably need to use `toEqual` instead.'); | ||
const SUGGEST_TO_EQUAL = exports.SUGGEST_TO_EQUAL = _chalk2.default.dim( | ||
'Looks like you wanted to test for object/array equality with strict `toBe` matcher. You probably need to use `toEqual` instead.'); | ||
const stringify = exports.stringify = function (object) { | ||
let maxDepth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; | ||
const stringify = exports.stringify = function (object) {let maxDepth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; | ||
const MAX_LENGTH = 10000; | ||
@@ -63,4 +58,4 @@ let result; | ||
min: true, | ||
plugins: PLUGINS }); | ||
plugins: PLUGINS | ||
}); | ||
} catch (e) { | ||
@@ -71,31 +66,17 @@ result = (0, _prettyFormat2.default)(object, { | ||
min: true, | ||
plugins: PLUGINS }); | ||
plugins: PLUGINS | ||
}); | ||
} | ||
return result.length >= MAX_LENGTH && maxDepth > 1 ? | ||
stringify(object, Math.floor(maxDepth / 2)) : | ||
result; | ||
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result; | ||
}; | ||
const highlightTrailingWhitespace = exports.highlightTrailingWhitespace = text => | ||
text.replace(/\s+$/gm, _chalk2.default.inverse('$&')); | ||
const highlightTrailingWhitespace = exports.highlightTrailingWhitespace = text => text.replace(/\s+$/gm, _chalk2.default.inverse('$&')); | ||
const printReceived = exports.printReceived = object => | ||
RECEIVED_COLOR(highlightTrailingWhitespace(stringify(object))); | ||
const printExpected = exports.printExpected = value => | ||
EXPECTED_COLOR(highlightTrailingWhitespace(stringify(value))); | ||
const printReceived = exports.printReceived = object => RECEIVED_COLOR(highlightTrailingWhitespace(stringify(object))); | ||
const printExpected = exports.printExpected = value => EXPECTED_COLOR(highlightTrailingWhitespace(stringify(value))); | ||
const printWithType = exports.printWithType = ( | ||
name, | ||
received, | ||
print) => | ||
{ | ||
const printWithType = exports.printWithType = (name, received, print) => { | ||
const type = (0, _jestGetType2.default)(received); | ||
return ( | ||
name + | ||
':' + ( | ||
type !== 'null' && type !== 'undefined' ? '\n ' + type + ': ' : ' ') + | ||
print(received)); | ||
return name + ':' + (type !== 'null' && type !== 'undefined' ? '\n ' + type + ': ' : ' ') + print(received); | ||
}; | ||
@@ -106,8 +87,3 @@ | ||
if (typeof expected !== 'undefined') { | ||
throw new Error( | ||
matcherHint('[.not]' + matcherName, undefined, '') + | ||
'\n\n' + | ||
'Matcher does not accept any arguments.\n' + | ||
printWithType('Got', expected, printExpected)); | ||
throw new Error(matcherHint('[.not]' + matcherName, undefined, '') + '\n\n' + 'Matcher does not accept any arguments.\n' + printWithType('Got', expected, printExpected)); | ||
} | ||
@@ -119,8 +95,3 @@ }; | ||
if (typeof actual !== 'number') { | ||
throw new Error( | ||
matcherHint('[.not]' + matcherName) + | ||
'\n\n' + | ||
`Received value must be a number.\n` + | ||
printWithType('Received', actual, printReceived)); | ||
throw new Error(matcherHint('[.not]' + matcherName) + '\n\n' + `Received value must be a number.\n` + printWithType('Received', actual, printReceived)); | ||
} | ||
@@ -132,16 +103,7 @@ }; | ||
if (typeof expected !== 'number') { | ||
throw new Error( | ||
matcherHint('[.not]' + matcherName) + | ||
'\n\n' + | ||
`Expected value must be a number.\n` + | ||
printWithType('Got', expected, printExpected)); | ||
throw new Error(matcherHint('[.not]' + matcherName) + '\n\n' + `Expected value must be a number.\n` + printWithType('Got', expected, printExpected)); | ||
} | ||
}; | ||
const ensureNumbers = exports.ensureNumbers = ( | ||
actual, | ||
expected, | ||
matcherName) => | ||
{ | ||
const ensureNumbers = exports.ensureNumbers = (actual, expected, matcherName) => { | ||
ensureActualIsNumber(actual, matcherName); | ||
@@ -151,26 +113,14 @@ ensureExpectedIsNumber(expected, matcherName); | ||
const pluralize = exports.pluralize = (word, count) => | ||
(NUMBERS[count] || count) + ' ' + word + (count === 1 ? '' : 's'); | ||
const pluralize = exports.pluralize = (word, count) => (NUMBERS[count] || count) + ' ' + word + (count === 1 ? '' : 's'); | ||
const matcherHint = exports.matcherHint = function ( | ||
matcherName) | ||
const matcherHint = exports.matcherHint = function (matcherName) { | ||
let received = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'received'; | ||
let expected = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'expected'; | ||
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
const comment = options.comment, | ||
isDirectExpectCall = options.isDirectExpectCall, | ||
isNot = options.isNot, | ||
secondArgument = options.secondArgument; | ||
{let received = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'received';let expected = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'expected';let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};const | ||
comment = options.comment,isDirectExpectCall = options.isDirectExpectCall,secondArgument = options.secondArgument; | ||
return ( | ||
_chalk2.default.dim('expect' + (isDirectExpectCall ? '' : '(')) + | ||
RECEIVED_COLOR(received) + | ||
_chalk2.default.dim((isDirectExpectCall ? '' : ')') + matcherName + '(') + | ||
EXPECTED_COLOR(expected) + ( | ||
secondArgument ? | ||
`${_chalk2.default.dim(', ')}${EXPECTED_COLOR(secondArgument)}` : | ||
'') + | ||
_chalk2.default.dim(`)${comment ? ` // ${comment}` : ''}`)); | ||
return _chalk2.default.dim('expect' + (isDirectExpectCall ? '' : '(')) + RECEIVED_COLOR(received) + (isNot ? `${_chalk2.default.dim(').')}not${_chalk2.default.dim(matcherName + '(')}` : _chalk2.default.dim((isDirectExpectCall ? '' : ')') + matcherName + '(')) + EXPECTED_COLOR(expected) + (secondArgument ? `${_chalk2.default.dim(', ')}${EXPECTED_COLOR(secondArgument)}` : '') + _chalk2.default.dim(`)${comment ? ` // ${comment}` : ''}`); | ||
}; |
{ | ||
"name": "jest-matcher-utils", | ||
"description": "A set of utility functions for expect and related packages", | ||
"version": "22.4.0", | ||
"version": "23.0.0-alpha.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6388
92
2