jest-matchers
Advanced tools
Comparing version 13.3.0-alpha.4eb0c908 to 13.3.0-alpha.8b48d59e
@@ -34,6 +34,7 @@ /** | ||
{ | ||
return function throwingMatcher(expected) { | ||
return function throwingMatcher(expected, options) { | ||
const result = matcher( | ||
actual, | ||
expected, | ||
options, | ||
{ args: arguments }); | ||
@@ -40,0 +41,0 @@ |
@@ -15,4 +15,4 @@ /** | ||
const diff = require('jest-diff'); | ||
const stringify = require('./utils').stringify; | ||
const diff = require('jest-diff');var _require = | ||
require('jest-matcher-utils');const stringify = _require.stringify; | ||
@@ -74,2 +74,32 @@ const matchers = { | ||
toBeNull(actual, expected) { | ||
ensureNoExpected(expected, 'toBeNull'); | ||
const pass = actual === null; | ||
const message = pass ? | ||
() => `expected '${ stringify(actual) }' not to be null` : | ||
() => `expected '${ stringify(actual) }' to be null`; | ||
return { message, pass };}, | ||
toBeDefined(actual, expected) { | ||
ensureNoExpected(expected, 'toBeDefined'); | ||
const pass = actual !== void 0; | ||
const message = pass ? | ||
() => `expected '${ stringify(actual) }' not to be defined` : | ||
() => `expected '${ stringify(actual) }' to be defined`; | ||
return { message, pass };}, | ||
toBeUndefined(actual, expected) { | ||
ensureNoExpected(expected, 'toBeUndefined'); | ||
const pass = actual === void 0; | ||
const message = pass ? | ||
() => `expected '${ stringify(actual) }' not to be undefined` : | ||
() => `expected '${ stringify(actual) }' to be undefined`; | ||
return { message, pass };}, | ||
toBeGreaterThan(actual, expected) { | ||
@@ -112,2 +142,56 @@ ensureNumbers(actual, expected, '.toBeGreaterThan'); | ||
`'${ expected }' (using <=)`; | ||
return { message, pass };}, | ||
toContain(actual, expected) { | ||
if (!Array.isArray(actual) && typeof actual !== 'string') { | ||
throw new Error( | ||
'.toContain() works only on arrays and strings. ' + | ||
`'${ typeof actual }': ` + | ||
`'${ stringify(actual) }' was passed`);} | ||
const pass = actual.indexOf(expected) != -1; | ||
const message = pass ? | ||
() => `expected '${ stringify(actual) }' not to contain ` + | ||
`'${ stringify(expected) }'` : | ||
() => `expected '${ stringify(actual) }' to contain ` + | ||
`'${ stringify(expected) }'`; | ||
return { message, pass };}, | ||
toBeCloseTo(actual, expected) {let precision = arguments.length <= 2 || arguments[2] === undefined ? 2 : arguments[2]; | ||
ensureNumbers(actual, expected, '.toBeCloseTo'); | ||
const pass = Math.abs(expected - actual) < Math.pow(10, -precision) / 2; | ||
const message = pass ? | ||
() => `expected '${ actual }' not to be close to '${ expected }'` + | ||
` with ${ precision }-digit precision` : | ||
() => `expected '${ actual }' to be close to '${ expected }'` + | ||
` with ${ precision }-digit precision`; | ||
return { message, pass };}, | ||
toMatch(actual, expected) { | ||
if (typeof actual !== 'string') { | ||
return { | ||
pass: false, | ||
message: `actual '${ actual }' is not a String` };} | ||
if (!(expected instanceof RegExp) && !(typeof expected == 'string')) { | ||
return { | ||
pass: false, | ||
message: `expected '${ expected }' is not a String or a RegExp` };} | ||
const pass = new RegExp(expected).test(actual); | ||
const message = pass ? | ||
() => `expected '${ actual }' not to match '${ stringify(expected) }'` : | ||
() => `expected '${ actual }' to match '${ stringify(expected) }'`; | ||
return { message, pass };} }; | ||
@@ -117,10 +201,10 @@ | ||
function ensureNoExpected(expected, matcherName) { | ||
const ensureNoExpected = (expected, matcherName) => { | ||
matcherName || (matcherName = 'This'); | ||
if (typeof expected !== 'undefined') { | ||
throw new Error(`${ matcherName } matcher does not accept any arguments`);}} | ||
throw new Error(`${ matcherName } matcher does not accept any arguments`);}}; | ||
function ensureNumbers(actual, expected, matcherName) { | ||
const ensureNumbers = (actual, expected, matcherName) => { | ||
matcherName || (matcherName = 'This matcher'); | ||
@@ -136,3 +220,3 @@ if (typeof actual !== 'number') { | ||
`${ matcherName } expected value should be a number. ` + | ||
`'${ typeof expected }' was passed`);}} | ||
`'${ typeof expected }' was passed`);}}; | ||
@@ -139,0 +223,0 @@ |
{ | ||
"name": "jest-matchers", | ||
"version": "13.3.0-alpha.4eb0c908", | ||
"version": "13.3.0-alpha.8b48d59e", | ||
"repository": { | ||
@@ -11,3 +11,4 @@ "type": "git", | ||
"dependencies": { | ||
"jest-diff": "^13.3.0-alpha.4eb0c908" | ||
"jest-diff": "^13.3.0-alpha.8b48d59e", | ||
"jest-matcher-utils": "^13.3.0-alpha.8b48d59e" | ||
}, | ||
@@ -14,0 +15,0 @@ "devDependencies": { |
@@ -17,4 +17,9 @@ /** | ||
export type RawMatcherFn = (expected: any, actual: any) => ExpectationResult; | ||
export type RawMatcherFn = ( | ||
expected: any, | ||
actual: any, | ||
options: any, | ||
) => ExpectationResult; | ||
export type ThrowingMatcherFn = (actual: any) => void; | ||
export type MatchersObject = {[id:string]: RawMatcherFn}; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9411
215
0
2
5