From 0f2fc07101cd23c029b900660fcbcffa81ce3d35 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Thu, 28 Nov 2024 07:49:21 +0100 Subject: [PATCH 1/2] Print cloud errors in console if present. --- src/composables/useAsync.ts | 2 ++ tests/composables/useAsync.test.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/composables/useAsync.ts b/src/composables/useAsync.ts index 0272c29..efec98d 100644 --- a/src/composables/useAsync.ts +++ b/src/composables/useAsync.ts @@ -61,6 +61,8 @@ export const useAsync = ( data.value = result; } } catch ( err: any ) { + console.error( err ); + if ( !shouldDiscardQuery() ) { error.value = err; } diff --git a/tests/composables/useAsync.test.ts b/tests/composables/useAsync.test.ts index 3165429..514ed2b 100644 --- a/tests/composables/useAsync.test.ts +++ b/tests/composables/useAsync.test.ts @@ -3,7 +3,7 @@ * For licensing, see LICENSE.md. */ -import { it, describe, expect } from 'vitest'; +import { it, vi, describe, expect } from 'vitest'; import { ref } from 'vue'; import { flushPromises } from '@vue/test-utils'; @@ -42,6 +42,20 @@ describe( 'useAsync', () => { expect( data.value ).toBe( null ); } ); + it( 'should print errors in console if the async function throws an error', async () => { + const errorInstance = new Error( 'test' ); + const consoleSpy = vi.spyOn( console, 'error' ); + + useAsync( async () => { + throw errorInstance; + } ); + + await flushPromises(); + + expect( consoleSpy ).toHaveBeenCalledWith( errorInstance ); + consoleSpy.mockRestore(); + } ); + it( 'should re-run async function on change ref inside async function', async () => { const refValue = ref( 0 ); const { data } = useAsync( async () => refValue.value ); From ee87969e633589251515f1829e2db2f52e3c5d58 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Thu, 28 Nov 2024 07:54:41 +0100 Subject: [PATCH 2/2] Adjust demo. --- demos/editor-cdn/App.vue | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/demos/editor-cdn/App.vue b/demos/editor-cdn/App.vue index c25defe..480916f 100644 --- a/demos/editor-cdn/App.vue +++ b/demos/editor-cdn/App.vue @@ -37,7 +37,7 @@