如何使用 Vitest 测试具有成帧器运动的 React 应用程序?



配置 →Vite+ 纱线 + 反应 + 成帧器运动

所以,一切都很好,直到我开始使用Framer-Motion...... 网页很好,帧运动可以无缝工作,但是当我尝试使用 vitest 时,只是为了渲染我的应用程序组件,它会给我一个错误: 错误

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;

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

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();
});
});

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

deps: {
registerNodeLoader: false
}

test下的vite.config.ts.

欲了解更多信息,我推荐 https://vitest.dev/config/#deps

最新更新