error.spec.ts 834 B

1234567891011121314151617181920212223242526
  1. import Vue from 'vue'
  2. import { invokeWithErrorHandling } from 'core/util/error'
  3. describe('invokeWithErrorHandling', () => {
  4. if (typeof Promise !== 'undefined') {
  5. it('should errorHandler call once when nested calls return rejected promise', done => {
  6. const originalHandler = Vue.config.errorHandler
  7. const handler = (Vue.config.errorHandler = vi.fn())
  8. const userCatch = vi.fn()
  9. const err = new Error('fake error')
  10. invokeWithErrorHandling(() => {
  11. return invokeWithErrorHandling(() => {
  12. return Promise.reject(err)
  13. })
  14. })
  15. .catch(userCatch)
  16. .then(() => {
  17. Vue.config.errorHandler = originalHandler
  18. expect(handler.mock.calls.length).toBe(1)
  19. expect(userCatch).toHaveBeenCalledWith(err)
  20. done()
  21. })
  22. })
  23. }
  24. })