Skip to content

Bug: "ReferenceError: Cannot access 'wrapper' before initialization" when testing v-model #2693

@souserge

Description

@souserge

Describe the bug

I'm trying to test v-model in a component that updates its model value in the setup function. I followed the suggestion from the official docs:
https://test-utils.vuejs.org/guide/advanced/v-model.html

However, since the update event callback relies on the wrapper object being defined, yet, since setup is run when mounting, the callback doesn't yet have wrapper initialized when it's run.

P.S. I'm not using the default parameter of defineModel in order to avoid the issue described here:
https://vuejs.org/api/sfc-script-setup.html#definemodel

Reproduction

https://stackblitz.com/edit/github-7j6ahrt8?file=src%2Fcomponents%2F__tests__%2FHelloWorld.spec.ts

Expected behavior

Such component behaviour can be tested.

Environment

OS: Linux 6.12 cpe:/o:nixos:nixos:25.05 25.05 (Warbler)
CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Memory: 1.14 GB / 7.51 GB
Container: Yes
Shell: 5.2.37 - /run/current-system/sw/bin/bash

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy