Skip to content

Commit da90eb8

Browse files
test(validation): unmount wrappers to fix pending fetch errors
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>
1 parent f6cae32 commit da90eb8

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/tests/views/Validation.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ describe('Validation.vue - Business Logic', () => {
162162
})
163163
})
164164

165+
afterEach(() => {
166+
wrapper.unmount()
167+
})
168+
165169
describe('canValidate computed property', () => {
166170
it('returns false when uuidToValidate is empty', () => {
167171
wrapper.setData({ uuidToValidate: '' })
@@ -520,6 +524,7 @@ describe('Validation.vue - Business Logic', () => {
520524
describe('created() - async signing activation from history.state', () => {
521525
const UUID = '550e8400-e29b-41d4-a716-446655440000'
522526
let stateGetter: ReturnType<typeof vi.spyOn>
527+
let localWrapper: ReturnType<typeof shallowMount> | null = null
523528

524529
beforeEach(() => {
525530
// Prevent the validate() floating Promise from crashing on
@@ -528,6 +533,8 @@ describe('Validation.vue - Business Logic', () => {
528533
})
529534

530535
afterEach(() => {
536+
localWrapper?.unmount()
537+
localWrapper = null
531538
stateGetter?.mockRestore()
532539
vi.mocked(axios.get).mockReset()
533540
})
@@ -539,7 +546,7 @@ describe('Validation.vue - Business Logic', () => {
539546
// This test verifies the OLD trigger (route params) no longer activates async signing.
540547
it('does NOT set isAsyncSigning via $route.params (Vue Router 5 drops non-path params)', () => {
541548
stateGetter = vi.spyOn(window.history, 'state', 'get').mockReturnValue({} as any)
542-
const localWrapper = shallowMount(Validation, {
549+
localWrapper = shallowMount(Validation, {
543550
mocks: {
544551
$route: { params: { uuid: UUID, isAsync: true }, query: {} },
545552
$router: { ...mockRouter, replace: vi.fn() },
@@ -553,7 +560,7 @@ describe('Validation.vue - Business Logic', () => {
553560

554561
it('does not set isAsyncSigning when history.state has no isAsync flag', () => {
555562
stateGetter = vi.spyOn(window.history, 'state', 'get').mockReturnValue({} as any)
556-
const localWrapper = shallowMount(Validation, {
563+
localWrapper = shallowMount(Validation, {
557564
mocks: {
558565
$route: { params: { uuid: UUID }, query: {} },
559566
$router: { ...mockRouter, replace: vi.fn() },
@@ -606,14 +613,15 @@ describe('Validation.vue - Business Logic', () => {
606613
})
607614

608615
it('does not fire confetti when document is not signed even if isAfterSigned is true', () => {
609-
const localWrapper = shallowMount(Validation, {
616+
const lw = shallowMount(Validation, {
610617
mocks: {
611618
$route: { params: { isAfterSigned: true }, query: {} },
612619
$router: mockRouter,
613620
},
614621
})
615-
localWrapper.vm.handleValidationSuccess({ status: 1, signers: [] })
622+
lw.vm.handleValidationSuccess({ status: 1, signers: [] })
616623
expect(mockAddConfetti).not.toHaveBeenCalled()
624+
lw.unmount()
617625
})
618626

619627
it('does not fire confetti when document is signed but neither isAfterSigned nor shouldFireAsyncConfetti is true', () => {

0 commit comments

Comments
 (0)