to-have-warned.ts — vue Source File
Architecture documentation for to-have-warned.ts, a typescript file in the vue codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 0164d137_47ae_d339_c3cd_2c3e6ea593ff["to-have-warned.ts"] c7fbd7f1_e080_f33c_4dc6_acfb8c6719db["vitest"] 0164d137_47ae_d339_c3cd_2c3e6ea593ff --> c7fbd7f1_e080_f33c_4dc6_acfb8c6719db 0e3275eb_033e_79be_7c0a_56de4c630110["vitest.setup.ts"] 0e3275eb_033e_79be_7c0a_56de4c630110 --> 0164d137_47ae_d339_c3cd_2c3e6ea593ff style 0164d137_47ae_d339_c3cd_2c3e6ea593ff fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { SpyInstance } from 'vitest'
expect.extend({
toHaveBeenWarned(received: string) {
asserted.add(received)
const passed = warn.mock.calls.some(args =>
String(args[0]).includes(received)
)
if (passed) {
return {
pass: true,
message: () => `expected "${received}" not to have been warned.`
}
} else {
const msgs = warn.mock.calls.map(args => args[0]).join('\n - ')
return {
pass: false,
message: () =>
`expected "${received}" to have been warned` +
(msgs.length
? `.\n\nActual messages:\n\n - ${msgs}`
: ` but no warning was recorded.`)
}
}
},
toHaveBeenWarnedLast(received: string) {
asserted.add(received)
const passed =
warn.mock.calls[warn.mock.calls.length - 1]?.[0].includes(received)
if (passed) {
return {
pass: true,
message: () => `expected "${received}" not to have been warned last.`
}
} else {
const msgs = warn.mock.calls.map(args => args[0]).join('\n - ')
return {
pass: false,
message: () =>
`expected "${received}" to have been warned last.\n\nActual messages:\n\n - ${msgs}`
}
}
},
toHaveBeenWarnedTimes(received: string, n: number) {
asserted.add(received)
let found = 0
warn.mock.calls.forEach(args => {
if (args[0].includes(received)) {
found++
}
})
if (found === n) {
return {
pass: true,
message: () => `expected "${received}" to have been warned ${n} times.`
}
} else {
return {
pass: false,
message: () =>
`expected "${received}" to have been warned ${n} times but got ${found}.`
}
}
},
toHaveBeenTipped(received: string) {
const passed = tip.mock.calls.some(args => args[0].includes(received))
if (passed) {
return {
pass: true,
message: () => `expected "${received}" not to have been tipped.`
}
} else {
const msgs = warn.mock.calls.map(args => args[0]).join('\n - ')
return {
pass: false,
message: () =>
`expected "${received}" to have been tipped` +
(msgs.length
? `.\n\nActual messages:\n\n - ${msgs}`
: ` but no tip was recorded.`)
}
}
}
})
let warn: SpyInstance
let tip: SpyInstance
const asserted: Set<string> = new Set()
beforeEach(() => {
asserted.clear()
warn = vi.spyOn(console, 'error')
tip = vi.spyOn(console, 'warn').mockImplementation(() => {})
warn.mockImplementation(() => {})
})
afterEach(() => {
const assertedArray = Array.from(asserted)
const nonAssertedWarnings = warn.mock.calls
.map(args => args[0])
.filter(received => {
return !assertedArray.some(assertedMsg => {
return String(received).includes(assertedMsg)
})
})
warn.mockRestore()
if (nonAssertedWarnings.length) {
throw new Error(
`test case threw unexpected warnings:\n - ${nonAssertedWarnings.join(
'\n - '
)}`
)
}
})
Domain
Dependencies
- vitest
Imported By
Source
Frequently Asked Questions
What does to-have-warned.ts do?
to-have-warned.ts is a source file in the vue codebase, written in typescript. It belongs to the VueCore domain.
What does to-have-warned.ts depend on?
to-have-warned.ts imports 1 module(s): vitest.
What files import to-have-warned.ts?
to-have-warned.ts is imported by 1 file(s): vitest.setup.ts.
Where is to-have-warned.ts in the architecture?
to-have-warned.ts is located at test/helpers/to-have-warned.ts (domain: VueCore, directory: test/helpers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free