Javascript RTL&x27;s TypeError:_react2.screen.getAllBy不是函数
在我的项目中,我成功地使用了Javascript RTL&x27;s TypeError:_react2.screen.getAllBy不是函数,javascript,reactjs,testing,jestjs,react-testing-library,Javascript,Reactjs,Testing,Jestjs,React Testing Library,在我的项目中,我成功地使用了@testing library/react中的render和screen,但是每次我使用screen.getAllBy或screen.getByRole或getByText以外的任何东西时,我都会遇到这样的错误。其中一个是, typeerror: _react2.screen.getAllBy is not a function 这是在使用screen.getAllBy时发生的 我的进口包括, import React from 'react'; import {
@testing library/react
中的render
和screen
,但是每次我使用screen.getAllBy
或screen.getByRole
或getByText
以外的任何东西时,我都会遇到这样的错误。其中一个是,
typeerror: _react2.screen.getAllBy is not a function
这是在使用screen.getAllBy
时发生的
我的进口包括,
import React from 'react';
import { render, screen } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom;
import TestComponent from './TestComponent';
我是否缺少导入或我的代码有问题
it (`Testing Component`, () => {
render(<BrowserRouter><TestComponent /></BrowserRouter>
expect(screen.getAllBy('li')).toBeInTheDocument();
});
it(`Testing Component`,()=>{
渲染(
expect(screen.getAllBy('li')).toBeInTheDocument();
});
getAllBy
只是查询的变体之一。完整的查询将是GetAllByBelText、getAllByRole
等。检查关于查询。之前阅读了几次文档。并行思考过多的最终结果。我很惊讶错过了如此琐碎的细节。--