@vitest/expect
Advanced tools
Comparing version 2.1.0-beta.6 to 2.1.0-beta.7
@@ -1319,3 +1319,3 @@ import { getType, stringify, isObject, assertTypes } from '@vitest/utils'; | ||
}); | ||
const assertIsMock = (assertion) => { | ||
function assertIsMock(assertion) { | ||
if (!isMockFunction(assertion._obj)) { | ||
@@ -1326,85 +1326,7 @@ throw new TypeError( | ||
} | ||
}; | ||
const getSpy = (assertion) => { | ||
} | ||
function getSpy(assertion) { | ||
assertIsMock(assertion); | ||
return assertion._obj; | ||
}; | ||
const ordinalOf = (i) => { | ||
const j = i % 10; | ||
const k = i % 100; | ||
if (j === 1 && k !== 11) { | ||
return `${i}st`; | ||
} | ||
if (j === 2 && k !== 12) { | ||
return `${i}nd`; | ||
} | ||
if (j === 3 && k !== 13) { | ||
return `${i}rd`; | ||
} | ||
return `${i}th`; | ||
}; | ||
const formatCalls = (spy, msg, showActualCall) => { | ||
if (spy.mock.calls) { | ||
msg += c.gray( | ||
` | ||
Received: | ||
${spy.mock.calls.map((callArg, i) => { | ||
let methodCall = c.bold( | ||
` ${ordinalOf(i + 1)} ${spy.getMockName()} call: | ||
` | ||
); | ||
if (showActualCall) { | ||
methodCall += diff(showActualCall, callArg, { | ||
omitAnnotationLines: true | ||
}); | ||
} else { | ||
methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n"); | ||
} | ||
methodCall += "\n"; | ||
return methodCall; | ||
}).join("\n")}` | ||
); | ||
} | ||
msg += c.gray( | ||
` | ||
Number of calls: ${c.bold(spy.mock.calls.length)} | ||
` | ||
); | ||
return msg; | ||
}; | ||
const formatReturns = (spy, results, msg, showActualReturn) => { | ||
msg += c.gray( | ||
` | ||
Received: | ||
${results.map((callReturn, i) => { | ||
let methodCall = c.bold( | ||
` ${ordinalOf(i + 1)} ${spy.getMockName()} call return: | ||
` | ||
); | ||
if (showActualReturn) { | ||
methodCall += diff(showActualReturn, callReturn.value, { | ||
omitAnnotationLines: true | ||
}); | ||
} else { | ||
methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n"); | ||
} | ||
methodCall += "\n"; | ||
return methodCall; | ||
}).join("\n")}` | ||
); | ||
msg += c.gray( | ||
` | ||
Number of calls: ${c.bold(spy.mock.calls.length)} | ||
` | ||
); | ||
return msg; | ||
}; | ||
} | ||
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) { | ||
@@ -1772,3 +1694,3 @@ const spy = getSpy(this); | ||
} | ||
return async (...args) => { | ||
return (...args) => { | ||
const promise = obj.then( | ||
@@ -1827,3 +1749,3 @@ (value) => { | ||
} | ||
return async (...args) => { | ||
return (...args) => { | ||
const promise = wrapper.then( | ||
@@ -1860,3 +1782,81 @@ (value) => { | ||
}; | ||
function ordinalOf(i) { | ||
const j = i % 10; | ||
const k = i % 100; | ||
if (j === 1 && k !== 11) { | ||
return `${i}st`; | ||
} | ||
if (j === 2 && k !== 12) { | ||
return `${i}nd`; | ||
} | ||
if (j === 3 && k !== 13) { | ||
return `${i}rd`; | ||
} | ||
return `${i}th`; | ||
} | ||
function formatCalls(spy, msg, showActualCall) { | ||
if (spy.mock.calls) { | ||
msg += c.gray( | ||
` | ||
Received: | ||
${spy.mock.calls.map((callArg, i) => { | ||
let methodCall = c.bold( | ||
` ${ordinalOf(i + 1)} ${spy.getMockName()} call: | ||
` | ||
); | ||
if (showActualCall) { | ||
methodCall += diff(showActualCall, callArg, { | ||
omitAnnotationLines: true | ||
}); | ||
} else { | ||
methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n"); | ||
} | ||
methodCall += "\n"; | ||
return methodCall; | ||
}).join("\n")}` | ||
); | ||
} | ||
msg += c.gray( | ||
` | ||
Number of calls: ${c.bold(spy.mock.calls.length)} | ||
` | ||
); | ||
return msg; | ||
} | ||
function formatReturns(spy, results, msg, showActualReturn) { | ||
msg += c.gray( | ||
` | ||
Received: | ||
${results.map((callReturn, i) => { | ||
let methodCall = c.bold( | ||
` ${ordinalOf(i + 1)} ${spy.getMockName()} call return: | ||
` | ||
); | ||
if (showActualReturn) { | ||
methodCall += diff(showActualReturn, callReturn.value, { | ||
omitAnnotationLines: true | ||
}); | ||
} else { | ||
methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n"); | ||
} | ||
methodCall += "\n"; | ||
return methodCall; | ||
}).join("\n")}` | ||
); | ||
msg += c.gray( | ||
` | ||
Number of calls: ${c.bold(spy.mock.calls.length)} | ||
` | ||
); | ||
return msg; | ||
} | ||
function getMatcherState(assertion, expect) { | ||
@@ -1863,0 +1863,0 @@ const obj = assertion._obj; |
{ | ||
"name": "@vitest/expect", | ||
"type": "module", | ||
"version": "2.1.0-beta.6", | ||
"version": "2.1.0-beta.7", | ||
"description": "Jest's expect matchers as a Chai plugin", | ||
@@ -35,4 +35,4 @@ "license": "MIT", | ||
"tinyrainbow": "^1.2.0", | ||
"@vitest/utils": "2.1.0-beta.6", | ||
"@vitest/spy": "2.1.0-beta.6" | ||
"@vitest/utils": "2.1.0-beta.7", | ||
"@vitest/spy": "2.1.0-beta.7" | ||
}, | ||
@@ -42,3 +42,3 @@ "devDependencies": { | ||
"rollup-plugin-copy": "^3.5.0", | ||
"@vitest/runner": "2.1.0-beta.6" | ||
"@vitest/runner": "2.1.0-beta.7" | ||
}, | ||
@@ -45,0 +45,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
148761
+ Added@vitest/pretty-format@2.1.0-beta.7(transitive)
+ Added@vitest/spy@2.1.0-beta.7(transitive)
+ Added@vitest/utils@2.1.0-beta.7(transitive)
- Removed@types/estree@1.0.5(transitive)
- Removed@vitest/pretty-format@2.1.0-beta.6(transitive)
- Removed@vitest/spy@2.1.0-beta.6(transitive)
- Removed@vitest/utils@2.1.0-beta.6(transitive)
- Removedestree-walker@3.0.3(transitive)
Updated@vitest/spy@2.1.0-beta.7
Updated@vitest/utils@2.1.0-beta.7