test: fix unexpected warning check when asserting same message for both conditions

This commit is contained in:
Evan You 2024-02-09 09:02:52 +08:00
parent 77a804b1d0
commit 5d48844670
1 changed files with 3 additions and 3 deletions

View File

@ -4,9 +4,9 @@ vi.stubGlobal('MathMLElement', class MathMLElement {})
expect.extend({ expect.extend({
toHaveBeenWarned(received: string) { toHaveBeenWarned(received: string) {
asserted.add(received)
const passed = warn.mock.calls.some(args => args[0].includes(received)) const passed = warn.mock.calls.some(args => args[0].includes(received))
if (passed) { if (passed) {
asserted.add(received)
return { return {
pass: true, pass: true,
message: () => `expected "${received}" not to have been warned.`, message: () => `expected "${received}" not to have been warned.`,
@ -25,10 +25,10 @@ expect.extend({
}, },
toHaveBeenWarnedLast(received: string) { toHaveBeenWarnedLast(received: string) {
asserted.add(received)
const passed = const passed =
warn.mock.calls[warn.mock.calls.length - 1][0].includes(received) warn.mock.calls[warn.mock.calls.length - 1][0].includes(received)
if (passed) { if (passed) {
asserted.add(received)
return { return {
pass: true, pass: true,
message: () => `expected "${received}" not to have been warned last.`, message: () => `expected "${received}" not to have been warned last.`,
@ -44,7 +44,6 @@ expect.extend({
}, },
toHaveBeenWarnedTimes(received: string, n: number) { toHaveBeenWarnedTimes(received: string, n: number) {
asserted.add(received)
let found = 0 let found = 0
warn.mock.calls.forEach(args => { warn.mock.calls.forEach(args => {
if (args[0].includes(received)) { if (args[0].includes(received)) {
@ -53,6 +52,7 @@ expect.extend({
}) })
if (found === n) { if (found === n) {
asserted.add(received)
return { return {
pass: true, pass: true,
message: () => `expected "${received}" to have been warned ${n} times.`, message: () => `expected "${received}" to have been warned ${n} times.`,