RTL's TypeError: _react2.screen.getAllBy is not a function
RTL's TypeError: _react2.screen.getAllBy is not a function
在我的项目中,我成功地使用了 @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();
});
getAllBy
只是查询的变体之一。完整的查询将是 getAllByLabelText, getAllByRole
等。检查 react-testing-library docs 关于查询。
在我的项目中,我成功地使用了 @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();
});
getAllBy
只是查询的变体之一。完整的查询将是 getAllByLabelText, getAllByRole
等。检查 react-testing-library docs 关于查询。