Skip to content

Composition API first Class support #876

@Xenoha

Description

@Xenoha

Hello Team,

This has been a great suite through the evolution of Vue, However, I feel like with this being a RC, there seems to be a lot of working around happening for simple Vue3 components. The documentation doesn't offer much for testing when using the compositions API and with the release of the setup SFC from the vue team this utils seems even further behind.

I'm not trying to be a bad news bear but I am dealing with a lot of issues which I would think should be first class with a test utils. At the very least, can the docs be updated to show composition api examples for each case?

  1. When using the globals.provide with the mount method, the values can be brought into a component as proxies or variable depending on how the user provides them in the parent. This isn't handled well inside the current mount method and when accessing an injected variable with the myVariable.value the test utils seems to no longer track correctly.

  2. The same occurs when bringing in props. Props are usually defined now through defineProps, and the user has the change to destructure with toRefs or use the prop itself. As soon as the user uses the property with toRefs the user is dealing with a proxy that the suite just doesn't handle.

The below highlights a simple example: (Just to highlight my thoughts above )
We have a simple component that renders the provided prop title. Then based on title and the injected type we grab some kind of data and set the ref data with the new data array.

<template>
  <div>
    {{ title }}
  </div>
  <div v-if="data.length" id="data">
    Has Data
  </div>
</template>
<script setup>
import { toRefs, ref, inject } from "vue";

const props = defineProps({
	title: { required: true, type: String },
});

const { title } = toRefs(props);

const type = inject("parentType"); // proxy`

const data = ref([]);

function getData() {
	 // get data based on the title and type.value then set it to data.value.
	 // data.value = newData
}

getData();
</script>

I would love your assistance here, but I don't see a way to test the template for the div#data element? I don't have a first class way to: expect(wrapper.find('#data').exists()).toBe(true).

To start I think I would have to:

const mockGetData = jest.fn()
global.provide = { parentType: 'something' }

Then type.value wouldn't exist because the utils doesn't handle this case, correct? Moreover, checking title.value in the setup won't have a value because I would provide props of title: 'Some Title'.

Using the composition API, how do I toggle the ref data? How do I both check the template text and do some calculation of the provided prop title? How do I toggle and add data to data.value?

Again, I have loved your tools and love what you did with the global.provide, teleport, and emitted() implementations. I just feel it's time we see first class support for the Composition API with clear documentation in a release candidate for Vue3.

As Always, assistance is always accepted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions