如何使用Vitest测试集成Framer Motion的React-ts应用?
Vitest渲染含Framer-Motion的React组件时出现tslib导出错误
环境配置
Vite + Yarn + React-ts + Framer-Motion
问题描述
项目原本运行正常,Framer-Motion功能也能正常工作,但在给App组件添加简单的<motion.button>后,使用Vitest渲染App组件时出现以下错误:
FAIL tests/unit/components.spec.tsx [ tests/unit/components.spec.tsx ] SyntaxError: Named export '__assign' not found. The requested module 'tslib' 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 'tslib'; const { __assign } = pkg;
添加Framer-Motion组件前,测试可以正常运行,测试代码如下:
import { describe, it, expect } from 'vitest'; import { render, screen } from '@testing-library/react'; import App from '../../src/App'; describe('App.vue', () => { it('should render the main input', () => { render(<App />); expect(screen.getByTestId('mainInput')).toBeDefined(); }); });
内容的提问来源于stack exchange,提问作者Duarte Elvas
相关产品推荐
相关产品推荐

