Skip to content

Commit

Permalink
test: fix unexpected warning check when asserting same message for bo…
Browse files Browse the repository at this point in the history
…th conditions
  • Loading branch information
yyx990803 committed Feb 9, 2024
1 parent 77a804b commit 5d48844
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/setup-vitest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ vi.stubGlobal('MathMLElement', class MathMLElement {})

expect.extend({
toHaveBeenWarned(received: string) {
asserted.add(received)
const passed = warn.mock.calls.some(args => args[0].includes(received))
if (passed) {
asserted.add(received)
return {
pass: true,
message: () => `expected "${received}" not to have been warned.`,
Expand All @@ -25,10 +25,10 @@ expect.extend({
},

toHaveBeenWarnedLast(received: string) {
asserted.add(received)
const passed =
warn.mock.calls[warn.mock.calls.length - 1][0].includes(received)
if (passed) {
asserted.add(received)
return {
pass: true,
message: () => `expected "${received}" not to have been warned last.`,
Expand All @@ -44,7 +44,6 @@ expect.extend({
},

toHaveBeenWarnedTimes(received: string, n: number) {
asserted.add(received)
let found = 0
warn.mock.calls.forEach(args => {
if (args[0].includes(received)) {
Expand All @@ -53,6 +52,7 @@ expect.extend({
})

if (found === n) {
asserted.add(received)
return {
pass: true,
message: () => `expected "${received}" to have been warned ${n} times.`,
Expand Down

0 comments on commit 5d48844

Please sign in to comment.