@vitest/expect
Advanced tools
Comparing version 0.34.4 to 0.34.5
import { getColors, stringify, isObject, assertTypes } from '@vitest/utils'; | ||
export { setupColors } from '@vitest/utils'; | ||
import { diff } from '@vitest/utils/diff'; | ||
import { AssertionError, util } from 'chai'; | ||
import { isMockFunction } from '@vitest/spy'; | ||
import { processError } from '@vitest/utils/error'; | ||
import { util } from 'chai'; | ||
@@ -668,2 +668,3 @@ const MATCHERS_OBJECT = Symbol.for("matchers-object"); | ||
const JestChaiExpect = (chai, utils) => { | ||
const { AssertionError } = chai; | ||
const c = () => getColors(); | ||
@@ -1071,7 +1072,4 @@ function def(name, fn) { | ||
msg = formatCalls(spy, msg); | ||
if (called && isNot || !called && !isNot) { | ||
const err = new Error(msg); | ||
err.name = "AssertionError"; | ||
throw err; | ||
} | ||
if (called && isNot || !called && !isNot) | ||
throw new AssertionError(msg); | ||
}); | ||
@@ -1083,3 +1081,3 @@ def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) { | ||
const isNot = utils.flag(this, "negate"); | ||
let msg = utils.getMessage( | ||
const msg = utils.getMessage( | ||
this, | ||
@@ -1093,8 +1091,4 @@ [ | ||
); | ||
if (pass && isNot || !pass && !isNot) { | ||
msg = formatCalls(spy, msg, args); | ||
const err = new Error(msg); | ||
err.name = "AssertionError"; | ||
throw err; | ||
} | ||
if (pass && isNot || !pass && !isNot) | ||
throw new AssertionError(formatCalls(spy, msg, args)); | ||
}); | ||
@@ -1145,7 +1139,16 @@ def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) { | ||
} else { | ||
let isThrow = false; | ||
try { | ||
obj(); | ||
} catch (err) { | ||
isThrow = true; | ||
thrown = err; | ||
} | ||
if (!isThrow && !isNot) { | ||
const message = utils.flag(this, "message") || "expected function to throw an error, but it didn't"; | ||
const error = { | ||
showDiff: false | ||
}; | ||
throw new AssertionError(message, error, utils.flag(this, "ssfi")); | ||
} | ||
} | ||
@@ -1216,3 +1219,3 @@ if (typeof expected === "function") { | ||
const isNot = utils.flag(this, "negate"); | ||
let msg = utils.getMessage( | ||
const msg = utils.getMessage( | ||
this, | ||
@@ -1226,8 +1229,4 @@ [ | ||
); | ||
if (pass && isNot || !pass && !isNot) { | ||
msg = formatReturns(spy, msg, value); | ||
const err = new Error(msg); | ||
err.name = "AssertionError"; | ||
throw err; | ||
} | ||
if (pass && isNot || !pass && !isNot) | ||
throw new AssertionError(formatReturns(spy, msg, value)); | ||
}); | ||
@@ -1268,4 +1267,5 @@ def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) { | ||
utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() { | ||
const error = new Error("resolves"); | ||
utils.flag(this, "promise", "resolves"); | ||
utils.flag(this, "error", new Error("resolves")); | ||
utils.flag(this, "error", error); | ||
const test = utils.flag(this, "vitest-test"); | ||
@@ -1287,3 +1287,8 @@ const obj = utils.flag(this, "object"); | ||
(err) => { | ||
throw new Error(`promise rejected "${String(err)}" instead of resolving`); | ||
const _error = new AssertionError( | ||
`promise rejected "${utils.inspect(err)}" instead of resolving`, | ||
{ showDiff: false } | ||
); | ||
_error.stack = error.stack.replace(error.message, _error.message); | ||
throw _error; | ||
} | ||
@@ -1298,4 +1303,5 @@ ); | ||
utils.addProperty(chai.Assertion.prototype, "rejects", function __VITEST_REJECTS__() { | ||
const error = new Error("rejects"); | ||
utils.flag(this, "promise", "rejects"); | ||
utils.flag(this, "error", new Error("rejects")); | ||
utils.flag(this, "error", error); | ||
const test = utils.flag(this, "vitest-test"); | ||
@@ -1314,3 +1320,8 @@ const obj = utils.flag(this, "object"); | ||
(value) => { | ||
throw new Error(`promise resolved "${String(value)}" instead of rejecting`); | ||
const _error = new AssertionError( | ||
`promise resolved "${utils.inspect(value)}" instead of rejecting`, | ||
{ showDiff: false } | ||
); | ||
_error.stack = error.stack.replace(error.message, _error.message); | ||
throw _error; | ||
}, | ||
@@ -1317,0 +1328,0 @@ (err) => { |
import { getColors, stringify, isObject, assertTypes } from '@vitest/utils'; | ||
export { setupColors } from '@vitest/utils'; | ||
import { diff } from '@vitest/utils/diff'; | ||
import { AssertionError, util } from 'chai'; | ||
import { isMockFunction } from '@vitest/spy'; | ||
import { processError } from '@vitest/utils/error'; | ||
import { util } from 'chai'; | ||
@@ -668,2 +668,3 @@ const MATCHERS_OBJECT = Symbol.for("matchers-object"); | ||
const JestChaiExpect = (chai, utils) => { | ||
const { AssertionError } = chai; | ||
const c = () => getColors(); | ||
@@ -1071,7 +1072,4 @@ function def(name, fn) { | ||
msg = formatCalls(spy, msg); | ||
if (called && isNot || !called && !isNot) { | ||
const err = new Error(msg); | ||
err.name = "AssertionError"; | ||
throw err; | ||
} | ||
if (called && isNot || !called && !isNot) | ||
throw new AssertionError(msg); | ||
}); | ||
@@ -1083,3 +1081,3 @@ def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) { | ||
const isNot = utils.flag(this, "negate"); | ||
let msg = utils.getMessage( | ||
const msg = utils.getMessage( | ||
this, | ||
@@ -1093,8 +1091,4 @@ [ | ||
); | ||
if (pass && isNot || !pass && !isNot) { | ||
msg = formatCalls(spy, msg, args); | ||
const err = new Error(msg); | ||
err.name = "AssertionError"; | ||
throw err; | ||
} | ||
if (pass && isNot || !pass && !isNot) | ||
throw new AssertionError(formatCalls(spy, msg, args)); | ||
}); | ||
@@ -1145,7 +1139,16 @@ def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) { | ||
} else { | ||
let isThrow = false; | ||
try { | ||
obj(); | ||
} catch (err) { | ||
isThrow = true; | ||
thrown = err; | ||
} | ||
if (!isThrow && !isNot) { | ||
const message = utils.flag(this, "message") || "expected function to throw an error, but it didn't"; | ||
const error = { | ||
showDiff: false | ||
}; | ||
throw new AssertionError(message, error, utils.flag(this, "ssfi")); | ||
} | ||
} | ||
@@ -1216,3 +1219,3 @@ if (typeof expected === "function") { | ||
const isNot = utils.flag(this, "negate"); | ||
let msg = utils.getMessage( | ||
const msg = utils.getMessage( | ||
this, | ||
@@ -1226,8 +1229,4 @@ [ | ||
); | ||
if (pass && isNot || !pass && !isNot) { | ||
msg = formatReturns(spy, msg, value); | ||
const err = new Error(msg); | ||
err.name = "AssertionError"; | ||
throw err; | ||
} | ||
if (pass && isNot || !pass && !isNot) | ||
throw new AssertionError(formatReturns(spy, msg, value)); | ||
}); | ||
@@ -1268,4 +1267,5 @@ def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) { | ||
utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() { | ||
const error = new Error("resolves"); | ||
utils.flag(this, "promise", "resolves"); | ||
utils.flag(this, "error", new Error("resolves")); | ||
utils.flag(this, "error", error); | ||
const test = utils.flag(this, "vitest-test"); | ||
@@ -1287,3 +1287,8 @@ const obj = utils.flag(this, "object"); | ||
(err) => { | ||
throw new Error(`promise rejected "${String(err)}" instead of resolving`); | ||
const _error = new AssertionError( | ||
`promise rejected "${utils.inspect(err)}" instead of resolving`, | ||
{ showDiff: false } | ||
); | ||
_error.stack = error.stack.replace(error.message, _error.message); | ||
throw _error; | ||
} | ||
@@ -1298,4 +1303,5 @@ ); | ||
utils.addProperty(chai.Assertion.prototype, "rejects", function __VITEST_REJECTS__() { | ||
const error = new Error("rejects"); | ||
utils.flag(this, "promise", "rejects"); | ||
utils.flag(this, "error", new Error("rejects")); | ||
utils.flag(this, "error", error); | ||
const test = utils.flag(this, "vitest-test"); | ||
@@ -1314,3 +1320,8 @@ const obj = utils.flag(this, "object"); | ||
(value) => { | ||
throw new Error(`promise resolved "${String(value)}" instead of rejecting`); | ||
const _error = new AssertionError( | ||
`promise resolved "${utils.inspect(value)}" instead of rejecting`, | ||
{ showDiff: false } | ||
); | ||
_error.stack = error.stack.replace(error.message, _error.message); | ||
throw _error; | ||
}, | ||
@@ -1317,0 +1328,0 @@ (err) => { |
{ | ||
"name": "@vitest/expect", | ||
"type": "module", | ||
"version": "0.34.4", | ||
"version": "0.34.5", | ||
"description": "Jest's expect matchers as a Chai plugin", | ||
@@ -33,8 +33,8 @@ "license": "MIT", | ||
"chai": "^4.3.7", | ||
"@vitest/utils": "0.34.4", | ||
"@vitest/spy": "0.34.4" | ||
"@vitest/utils": "0.34.5", | ||
"@vitest/spy": "0.34.5" | ||
}, | ||
"devDependencies": { | ||
"picocolors": "^1.0.0", | ||
"@vitest/runner": "0.34.4" | ||
"@vitest/runner": "0.34.5" | ||
}, | ||
@@ -41,0 +41,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106173
3062
+ Added@vitest/spy@0.34.5(transitive)
+ Added@vitest/utils@0.34.5(transitive)
- Removed@vitest/spy@0.34.4(transitive)
- Removed@vitest/utils@0.34.4(transitive)
Updated@vitest/spy@0.34.5
Updated@vitest/utils@0.34.5