Inconsistent behaviour when using components from an AE's provided UI Kit that extend Quasar components when run in Vitest

Aperta
#388 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
frontend, testing

Direzione di ricerca

Build the UI portion of quasar-test-ui with npm run build, then run npm run test:unit in quasar-test-app. Compare the q-btn and q-btn-dropdown cases with the corresponding my-button and my-button-dropdown cases under tests/vitest/*. Done means wrapped components register clicks and avoid the reported Platform plugin error in Vitest.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

When using a Quasar app extension that provides UI components that extend Quasar components, the components exhibit mixed behaviour when run inside a Vitest testing environment (which they do not exhibit when simply used in a host app).

Example

Writing a simple test that uses q-btn to increment a counter with clicks works fine and tests pass. However, switching these components with ones from an AE's UI Kit (i.e. my-button) that do nothing but return a q-btn from their render function causes the click function to no longer get called properly. Similarly, a q-btn-dropdown works fine and tests pass but a custom my-button-dropdown that simply returns a q-btn-dropdown causes a strange error that seems to originate from the Platform plugin.

From app extension's UI Kit:

import { h } from 'vue'
import { QBtn } from 'quasar'

export default {
  name: 'MyButton',

  setup (props, { attrs}) {
    return () => h(QBtn, {
      ...props,
      ...attrs,
      class: 'my-button'
    })
  }
}

Simple test case in host app using Vitest

<template>
  <div>
    <p>{{ title }}</p>

    <p>Clicks on button: {{ clickCount }}</p>

    <my-button @click="increment" />
    <my-button-dropdown @click="increment" />

    <q-btn @click="increment" />
    <q-btn-dropdown @click="increment" />

  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const props = withDefaults(
  defineProps<{
    title: string;
  }>(),
  {
    title: 'Hello!',
  },
);

const clickCount = ref(0);
function increment() {
  clickCount.value += 1;
  return clickCount.value;
}
</script>

The test for this case:

describe('example Button', () => {
  it('should register a click event and perform it', async () => {
    const wrapper = mount(ExampleButton, {
      props: {
        title: 'Hello'
      },
    });
    expect(wrapper.vm.clickCount).toBe(0);
    await wrapper.find('.my-button').trigger('click');
    expect(wrapper.vm.clickCount).toBe(1);
  });
});

results in:

Image

or this with q-btn-dropdown case:

Image
Reproduction

This issue spans two repos: one for the app extension/UI kit, and another for the Vitest test case that uses the component from the UI kit.

To reproduce:

  1. Install dependencies and build the ui portion of the quasar-test-ui repo using npm run build
  2. Ensure the quasar-test-ui repo is properly linked as a dependency in the quasar-test-app and install dependencies
  3. Run npm run test:unit in the quasar-test-app and play around with the examples commented in/out under the tests/vitest/* directory (switch q-btn for my-button, q-btn-dropdown for my-button-dropdown, etc)
Lingua principale
TypeScript
Stelle
184
Fork
67
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quasarframework/quasar-testing

Tutte le issue di quasarframework/quasar-testing

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.