error.test.ts 690 B

1234567891011121314151617181920212223242526
  1. import { describe, expect, it, vi } from 'vitest'
  2. import { debugWarn, throwError } from '..'
  3. describe('error', () => {
  4. it('throwError should work', () => {
  5. expect(() =>
  6. throwError('scope', 'message')
  7. ).toThrowErrorMatchingInlineSnapshot('"[scope] message"')
  8. })
  9. it('debugWarn should work', () => {
  10. const warnFn = vi.spyOn(console, 'warn').mockImplementation(() => vi.fn)
  11. debugWarn('scope', 'message')
  12. debugWarn(new SyntaxError('custom error'))
  13. expect(warnFn.mock.calls).toMatchInlineSnapshot(`
  14. [
  15. [
  16. [ElementPlusError: [scope] message],
  17. ],
  18. [
  19. [SyntaxError: custom error],
  20. ],
  21. ]
  22. `)
  23. })
  24. })