Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use [email protected] with vue 2.7 script setup #2045

Closed
arthurrmp opened this issue Dec 20, 2022 · 1 comment
Closed

Can't use [email protected] with vue 2.7 script setup #2045

arthurrmp opened this issue Dec 20, 2022 · 1 comment

Comments

@arthurrmp
Copy link

Subject of the issue

When using [email protected] with [email protected], I'm not able to test SFC components made with script setup syntactic sugar.

Steps to reproduce

  1. Created a new project using vue-cli (vue 2)
  2. update the Vue version: yarn install [email protected]
  3. create any component with script setup syntactic sugar
  4. try to add any unit test to this component

Expected behaviour

It should pass the simple test.

Actual behaviour

// App.vue
<template>
  <div id="app">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  setup() {
    const msg = "new message";
    return {
      msg,
    };
  },
});
</script>
// AppScriptSetup.vue
<template>
  <div id="app">
    <h1>{{ msg }}</h1>
  </div>
</template>

<script lang="ts" setup>
const msg = "new message";
</script>
import { shallowMount } from "@vue/test-utils";
import App from "@/App.vue";
import AppScriptSetup from "@/AppScriptSetup.vue";

describe("App.vue", () => {
  it("renders the App", () => {
    const msg = "new message";
    const wrapper = shallowMount(App);
    expect(wrapper.text()).toBe(msg); // This works as expected 
  });
});

describe("AppScriptSetup.vue", () => {
  it("renders the AppScriptSetup", () => {
    const msg = "new message";
    const wrapper = shallowMount(AppScriptSetup);
    expect(wrapper.text()).toBe(msg); // This fails with the error: [Vue warn]: Property or method "msg" is not defined on the instance but referenced during render.
  });
});

Open a terminal and run yarn test:unit at https://codesandbox.io/p/github/arthurrmp/vue-2-script-setup-test-utils to see it live.
The same code works as intended using Vue 3, as seen at https://codesandbox.io/p/github/arthurrmp/vue-3-script-setup-test-utils

Possible Solution

I've not been able to find any alternatives.

@arthurrmp
Copy link
Author

duplicated of #1983

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant