小编Moh*_*ini的帖子

Vitest 错误:React 刷新前导码未加载。有问题

我是测试新手,我尝试使用 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 …

testing typescript mern vite vitest

2
推荐指数
1
解决办法
3969
查看次数

标签 统计

mern ×1

testing ×1

typescript ×1

vite ×1

vitest ×1