当我在 Vite 应用程序中运行测试时,出现错误“错误:预期表达式”

问题描述 投票:0回答:1

我的测试由于某些奇怪的原因失败了。

下面是包含整个代码的文件,我不确定为什么它会失败,即使我使用了我希望像“getByPlaceholderText”一样工作的不同匹配器和属性,它仍然会失败并出现相同的错误。

sum.test.js

/* eslint-disable no-undef */
import React from 'react';
import { render, screen } from '@testing-library/react';

function InputComponent() {
    return <input type="text" name="userName" />;
}

test('renders input with aria-label', () => {
    render(<InputComponent />);
    const inputElement = screen.getByRole('textbox');
    expect(inputElement).toBeInTheDocument();
});

控制台中的错误提示,

 FAIL  sum.test.js [ sum.test.js ]
Error: Expression expected
 ❯ getRollupError ../../../.nvm/versions/node/v20.5.0/lib/node_modules/vitest/node_modules/rollup/dist/es/shared/parseAst.js:396:41

 Test Files  1 failed (1)
      Tests  no tests
   Start at  15:08:31
   Duration  0ms
reactjs testing jestjs react-testing-library vitest
1个回答
0
投票

我也有同样的问题。你成功解决这个问题了吗?

© www.soinside.com 2019 - 2024. All rights reserved.