From cab254e385ce98f5b7f26ed9ef570807adcc98ef Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Thu, 26 Feb 2026 18:32:37 -0300 Subject: [PATCH] test(validation): unmount wrappers to fix pending fetch errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vitest was reporting 13 unhandled rejections with 'Closing rpc while fetch was pending' in Validation.spec.ts. Root cause: Vue instances were never unmounted between tests, so their beforeUnmount hooks never ran — isActiveView stayed true and background microtasks (validate, refreshAfterAsyncSigning) kept firing after the worker started winding down. Fixes: - Add outer afterEach(() => wrapper.unmount()) for the main wrapper - Track local wrappers in the created() describe at scope level and unmount them in afterEach - Unmount the inline localWrapper in the handleValidationSuccess describe immediately after use Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- src/tests/views/Validation.spec.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/tests/views/Validation.spec.ts b/src/tests/views/Validation.spec.ts index 4c2f992f3f..0165677a7b 100644 --- a/src/tests/views/Validation.spec.ts +++ b/src/tests/views/Validation.spec.ts @@ -162,6 +162,10 @@ describe('Validation.vue - Business Logic', () => { }) }) + afterEach(() => { + wrapper.unmount() + }) + describe('canValidate computed property', () => { it('returns false when uuidToValidate is empty', () => { wrapper.setData({ uuidToValidate: '' }) @@ -520,6 +524,7 @@ describe('Validation.vue - Business Logic', () => { describe('created() - async signing activation from history.state', () => { const UUID = '550e8400-e29b-41d4-a716-446655440000' let stateGetter: ReturnType + let localWrapper: ReturnType | null = null beforeEach(() => { // Prevent the validate() floating Promise from crashing on @@ -528,6 +533,8 @@ describe('Validation.vue - Business Logic', () => { }) afterEach(() => { + localWrapper?.unmount() + localWrapper = null stateGetter?.mockRestore() vi.mocked(axios.get).mockReset() }) @@ -539,7 +546,7 @@ describe('Validation.vue - Business Logic', () => { // This test verifies the OLD trigger (route params) no longer activates async signing. it('does NOT set isAsyncSigning via $route.params (Vue Router 5 drops non-path params)', () => { stateGetter = vi.spyOn(window.history, 'state', 'get').mockReturnValue({} as any) - const localWrapper = shallowMount(Validation, { + localWrapper = shallowMount(Validation, { mocks: { $route: { params: { uuid: UUID, isAsync: true }, query: {} }, $router: { ...mockRouter, replace: vi.fn() }, @@ -553,7 +560,7 @@ describe('Validation.vue - Business Logic', () => { it('does not set isAsyncSigning when history.state has no isAsync flag', () => { stateGetter = vi.spyOn(window.history, 'state', 'get').mockReturnValue({} as any) - const localWrapper = shallowMount(Validation, { + localWrapper = shallowMount(Validation, { mocks: { $route: { params: { uuid: UUID }, query: {} }, $router: { ...mockRouter, replace: vi.fn() }, @@ -606,14 +613,15 @@ describe('Validation.vue - Business Logic', () => { }) it('does not fire confetti when document is not signed even if isAfterSigned is true', () => { - const localWrapper = shallowMount(Validation, { + const lw = shallowMount(Validation, { mocks: { $route: { params: { isAfterSigned: true }, query: {} }, $router: mockRouter, }, }) - localWrapper.vm.handleValidationSuccess({ status: 1, signers: [] }) + lw.vm.handleValidationSuccess({ status: 1, signers: [] }) expect(mockAddConfetti).not.toHaveBeenCalled() + lw.unmount() }) it('does not fire confetti when document is signed but neither isAfterSigned nor shouldFireAsyncConfetti is true', () => {