gpt4 book ai didi

ag-grid - 如何使用 testing-library 测试 ag-grid 中的内容?

转载 作者:行者123 更新时间:2023-12-04 11:58:59 24 4
gpt4 key购买 nike

我正在尝试编写一些简单的测试,让我想要呈现的标题和数据按预期显示。我创建了一个 repo - https://github.com/olore/ag-grid-testing-library繁殖。该表在浏览器中打开时看起来就像我期望的那样。

<AgGridReact
columnDefs={ /* First 2 always findable, others never */
[
{ field: "make" },
{ field: "model" },
{ field: "price" },
{ field: "color" },
]}
rowData={
[{
make: "Toyota",
model: "Celica",
price: "35000",
color: "blue"
}]
}
pagination={true}></AgGridReact>
和测试
test('renders all the headers', async () => {
const { getByText } = render(<GridExample />);
expect(getByText("Make")).toBeInTheDocument(); // PASS
expect(getByText("Model")).toBeInTheDocument(); // PASS
expect(getByText("Price")).toBeInTheDocument(); // FAIL
expect(getByText("Color")).toBeInTheDocument(); // FAIL
});
在本地,前 2 列标题和数据是可访问的,但没有呈现其他列,正如我在 testing-library 的输出中看到的那样。我正在使用 --env=jsdom-fourteen正如其他帖子所推荐的那样。
奇怪的是,当在这个 repo 的代码和框中时,没有为测试呈现标题或数据,与本地一样,浏览器看起来是正确的。
https://codesandbox.io/s/gallant-framework-e54c7 .然后我尝试等待 gridReady https://codesandbox.io/s/intelligent-minsky-wl17y ,但这并没有什么区别。
编辑:还尝试直接调用 onGridReady 中的函数,同样的问题(前 2 列通过,第二个 2 失败)
test('renders all the headers', async (done) => {
let page;

const onReady = () => {
expect(page.getByText("Make")).toBeInTheDocument(); // PASS
expect(page.getByText("Model")).toBeInTheDocument(); // PASS
expect(page.getByText("Price")).toBeInTheDocument(); // FAIL
expect(page.getByText("Color")).toBeInTheDocument(); // FAIL
done();
}
page = render(<GridExample ready={onReady}/>);
});

最佳答案

ag-grid 使用 Column Virtualisation ,所以这里的解决方案似乎是通过 suppressColumnVirtualisation 禁用它<AgGridReact> 上的属性元素。

  <AgGridReact
suppressColumnVirtualisation={true}
...
繁荣!所有测试通过!
实际上,在测试期间只抑制它可能是理想的:
        suppressColumnVirtualisation={process.env.NODE_ENV === "test"}

关于ag-grid - 如何使用 testing-library 测试 ag-grid 中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63969843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com