vuejs / vuejs/test-utils

Stubs rendering default props

Open
#945 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement
Dominant language
TypeScript
Stars
1.2k
Forks
291
Avg merge
1d 9h
Merged PRs (30d)
18

Description

When rendering snapshots, stubbed components are actually being evaluated in order to apply the default props to the element.

For example if my component imports and contains the following code:

<Button
      ref="cancel-button"
      label="Cancel"
      :disabled="isLoading"
      icon="pi pi-times"
      @click="cancelClickHandler"
      class="p-button-text"
    />

And I stub out the Button component in my test

mountOptions = {
      global: {
        stubs: ["Button"]
      }
    }

My snapshot will render with
<button-stub label="Cancel" icon="pi pi-times" iconpos="left" loading="false" loadingicon="pi pi-spinner pi-spin" disabled="false" class="p-button-text"></button-stub>

iconpos="left" and loadingicon="pi pi-spinner pi-spin" should not be rendered.

This is annoying for me because whenever I update my Button component my snapshots for anything using the Button component need to be updated. I already have my Button component covered with its own tests so this is unnecessary.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing snapshot rendering and component stubbing in Vue Test Utils, focusing on how stubbed components receive default props. Reproduce the Button example and compare the snapshot with the expected stub output. Done means stub snapshots no longer include default props from the original component, while explicitly passed props remain visible.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.