({
silent,
attachProps,
enableWarnHandler,
enableErrorHandler,
enableConsole,
vm,
optionsUndefined = false,
}: TestHarnessOpts)
| 250 | } |
| 251 | |
| 252 | const testHarness = ({ |
| 253 | silent, |
| 254 | attachProps, |
| 255 | enableWarnHandler, |
| 256 | enableErrorHandler, |
| 257 | enableConsole, |
| 258 | vm, |
| 259 | optionsUndefined = false, |
| 260 | }: TestHarnessOpts) => { |
| 261 | vi.useFakeTimers(); |
| 262 | const providedErrorHandlerSpy = vi.fn(); |
| 263 | const warnHandlerSpy = vi.fn(); |
| 264 | const consoleErrorSpy = vi.fn(); |
| 265 | |
| 266 | const client: any = { |
| 267 | captureException: vi.fn(async () => Promise.resolve()), |
| 268 | }; |
| 269 | setCurrentClient(client); |
| 270 | |
| 271 | const app: Vue = { |
| 272 | config: { |
| 273 | silent: !!silent, |
| 274 | }, |
| 275 | mixin: vi.fn(), |
| 276 | }; |
| 277 | |
| 278 | if (enableErrorHandler) { |
| 279 | app.config.errorHandler = providedErrorHandlerSpy; |
| 280 | } |
| 281 | |
| 282 | if (enableWarnHandler) { |
| 283 | app.config.warnHandler = warnHandlerSpy; |
| 284 | } |
| 285 | |
| 286 | /* eslint-disable no-global-assign */ |
| 287 | if (enableConsole) { |
| 288 | // I need to re-assign the whole console |
| 289 | // because at some point it can be set to undefined |
| 290 | // @ts-expect-error for the sake of testing |
| 291 | console = { error: consoleErrorSpy }; |
| 292 | } else { |
| 293 | // @ts-expect-error for the sake of testing |
| 294 | console = undefined; |
| 295 | } |
| 296 | /* eslint-enable no-global-assign */ |
| 297 | |
| 298 | const options: Options | undefined = optionsUndefined |
| 299 | ? undefined |
| 300 | : { |
| 301 | attachProps: !!attachProps, |
| 302 | tracingOptions: {}, |
| 303 | trackComponents: [], |
| 304 | timeout: 0, |
| 305 | hooks: [] as Operation[], |
| 306 | }; |
| 307 | |
| 308 | return { |
| 309 | run: () => { |
no test coverage detected