首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Vitest测试具有框架动作的React应用程序?

如何使用Vitest测试具有框架动作的React应用程序?
EN

Stack Overflow用户
提问于 2022-08-10 16:30:50
回答 1查看 179关注 0票数 1

配置Vite+纱+React ts+ Framer-Motion

所以,一切都很好直到我开始和Framer-Motion合作.网页很好,而且框架运动是无缝工作的,但是当我尝试使用vitest时,只是为了呈现我的App组件,它给了我一个错误:错误

代码语言:javascript
复制
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;

在我将一个简单的<motion.button>添加到App之前,它自己用来运行良好的测试。测试:

代码语言:javascript
复制
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();
  });
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-11 08:43:46

好了,解决了!所以我唯一需要做的就是

代码语言:javascript
复制
deps: {
  registerNodeLoader: false
}

vite.config.ts下的test

有关更多信息,我推荐https://vitest.dev/config/#deps

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73309769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档