我是测试新手,我尝试使用 vitest 来测试我的 Mern 社交媒体应用程序。寻找使用 vitest 测试 React 组件的参考资料,我发现这篇文章https://eternaldev.com/blog/testing-a-react-application-with-vitest。接下来,当我尝试渲染组件时,我收到错误React刷新前导码未加载。运行测试时出现问题。以下是相关代码:
注册.test.tsx
import { expect, test, describe } from 'vitest';
import { render, screen } from '@testing-library/react';
// import Register from '../../components/Authentication/Register';
import Fake from '../../Fake';
describe('Registration Component Full functionality testing', () => {
test("should be showing Signup heading", () => {
render(<Fake />);
expect(screen.getByText(/Fake/i)).toBeDefined()
})
})
Run Code Online (Sandbox Code Playgroud)
假的.tsx
import React from 'react'
const Fake: React.FC = () => {
return (
<div>Fake</div>
)
}
export default Fake
Run Code Online (Sandbox Code Playgroud)
vite.config.ts …