Skip to content

VueWrapper typing problem #3808

@stevemandl

Description

@stevemandl

Observed:
While editing the following test file,

// App.spec.ts
import { mount } from "@vue/test-utils"
import { describe, it, expect } from "vitest"
import App from "../src/App.vue"

describe("App", () => {
    it("toggles", () => {
        const wrapper = mount<typeof App>(App)
        expect(wrapper.element.tagName).toBe("DIV")
        expect(wrapper.vm.editButton).toBeFalsy()
    });
});

for this .vue file:

// App.vue
<template>
    <div> <input type="button" :value="String(editButton)" @click="editButton = !editButton" /> </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
const editButton = ref<boolean>(false)
</script>

the type of wrapper.vm is ComponentPublicInstance instead of the specific type of the component. This causes the following to be displayed:
image
However, the test runs without a problem.

Expected behavior: Volar will reference the component type when validating code, and not report a problem if there isn't one.

Example project to reproduce problem: https://github.com/stevemandl/vitest_sample

Activity

so1ve

so1ve commented on Dec 19, 2023

@so1ve
Member

🤔 Shall we expose all variables in <script setup> block?

stevemandl

stevemandl commented on Dec 19, 2023

@stevemandl
Author

@so1ve I'm not sure if that question was for me or not, but I'll lend my 2 cents:
vuejs/test-utils#931 is where VTU exposed everything on wrapper.vm to allow the sample test pass. I'm not sure if this is a problem with VTU or volar, but running vitest from the console passes. Since I am just seeing the problem message in vscode so I thought I would start by reporting it here. Sorry I can't be more help.

Clarkkkk

Clarkkkk commented on Feb 3, 2024

@Clarkkkk

Just for reference, there is more context in vuejs/test-utils#972, in which @pikax mentions that he is doing some work on vuejs/core#4465 (now vuejs/core#9556) to improve types and may help solve this issue.

added theissue type on Feb 21, 2025
added
good reproduction ✨This issue provides a good reproduction, we will be able to investigate it first
on Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good reproduction ✨This issue provides a good reproduction, we will be able to investigate it firstupstream: core

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stevemandl@johnsoncodehk@so1ve@kermanx@Clarkkkk

        Issue actions

          VueWrapper typing problem · Issue #3808 · vuejs/language-tools