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

vitest with mount from @vue/test-utils SyntaxError (0.20.3) #1793

Closed
6 tasks done
michaelmano opened this issue Aug 5, 2022 · 1 comment
Closed
6 tasks done

vitest with mount from @vue/test-utils SyntaxError (0.20.3) #1793

michaelmano opened this issue Aug 5, 2022 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@michaelmano
Copy link

Describe the bug

Vitest version 0.19.1 is fine with this, However after upgrading to 0.20.3 when mount from "@vue/test-utils": "^2.0.2",
causes the following error

 FAIL  src/components/HelloWorld.test.ts [ src/components/HelloWorld.test.ts ]
SyntaxError: Named export 'BaseTransition' not found. The requested module 'vue' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'vue';
const { transformVNodeArgs, Transition, BaseTransition, defineComponent, h, TransitionGroup, Teleport, nextTick, setDevtoolsHook, shallowReactive, reactive, isRef, createApp, computed } = pkg;

Reproduction

Create a new vite project, install viteest 0.20.3 and @vue/test-utils any version.

Then create a new test file with the following

import { mount } from '@vue/test-utils';
import {
  expect, describe, it,
} from 'vitest';
import HelloWorld from './HelloWorld.vue';

describe('HelloWorld.vue', () => {
  it('should exist', async () => {
    expect(HelloWorld).toBeTruthy();
  });

  it('should display header text', async () => {
    const msg = 'HelloWorld';
    const wrapper = mount(HelloWorld, {
      props: {
        msg,
      },
    });
    expect(wrapper.find('h1').text()).toEqual(msg);
  });
});

This will cause the error.

Revert vitest to 0.19.1 and its working as expected.

System Info

System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 977.92 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Chrome: 104.0.5112.79
    Firefox: 91.0.2
    Safari: 14.1.1
  npmPackages:
    @vitejs/plugin-vue: ^3.0.0 => 3.0.1
    vite: ^3.0.0 => 3.0.4
    vitest: ^0.19.1 => 0.19.1

Used Package Manager

npm

Validations

@michaelmano michaelmano changed the title vitest with mount from @vue/test-utils SyntaxError vitest with mount from @vue/test-utils SyntaxError (0.20.3) Aug 5, 2022
@sheremet-va
Copy link
Member

Duplicate of #1753
See workaround there.

@sheremet-va sheremet-va added the duplicate This issue or pull request already exists label Aug 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants