Thanks to visit codestin.com
Credit goes to github.com

Skip to content

unUnmounted hook not being called with enableAutoUnmount #2105

@borisovg

Description

@borisovg

Subject of the issue

When using enableAutoUnmount(afterEach); I am expecting the onUnmounted hook to be called after every test, but this is not happening.

Steps to reproduce

import { enableAutoUnmount, mount } from "@vue/test-utils";
import { afterEach } from "node:test";
import { describe, it, expect } from "vitest";
import { defineComponent, onMounted, onUnmounted } from "vue";

const template = "<div>Test</div>";

const TestComponent = defineComponent({
  setup() {
    onMounted(() => console.log("MOUNTED"));
    onUnmounted(() => console.log("UNMOUNTED"));
  },
  template,
});

describe("Test", () => {
  enableAutoUnmount(afterEach);

  for (const i of [1, 2, 3]) {
    it(`test ${i}`, () => {
      const wrapper = mount(TestComponent);
      expect(wrapper.html()).toEqual(template);
    });
  }
});

Expected behaviour

Expecting to see "UNMOUNTED" logged 3 times.

Actual behaviour

TAP version 13
stdout | src/Test.test.ts > Test > test 1
MOUNTED

stdout | src/Test.test.ts > Test > test 2
MOUNTED

stdout | src/Test.test.ts > Test > test 3
MOUNTED

 ✓ src/Test.test.ts (3 tests) 22ms
   ✓ Test > test 1 17ms
   ✓ Test > test 2 2ms
   ✓ Test > test 3 2ms

 Test Files  1 passed (1)
      Tests  3 passed (3)
   Start at  15:39:50
   Duration  121ms

Package versions

  • "vue": "^3.5.17",
  • "@vue/test-utils": "^2.4.6",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions