重新工具UT从组件读取数据

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

嗨,我是重组的新手,我正在尝试在重组中添加单元测试。在我的测试中,我尝试访问表的数据,但不知何故,数据始终为“空”,即使我可以看到失败日志中的数据中有内容。

await my_search_button.setValue("Test Name");
await new Promise(r => setTimeout(r, 6000));
assertCondition(table1.data ===  "Test Name"); 
/* When I execute this line I can see in my 
failed log that my data is

table1.data: {
"associated_company_name": [
"Test Name"
], 

*/

/* But when I try to access the associated_company_name in data like below, I will get an error message : "Cannot read properties of null (reading 'associated_company_name')" */

assertCondition(table1.data.associated_company_name ===  "Test Name"); 
retool
1个回答
0
投票

也许数据尚未加载...您可以如何等待它加载:

await my_search_button.setValue("Test Name");

function waitForTableData() {
  return new Promise((resolve) => {
    const interval = setInterval(() => {
      if (table1.data && table1.data.associated_company_name) {
        clearInterval(interval);
        resolve();
      }
    }, 100); // check every 100ms
  });
}

await waitForTableData();

assertCondition(table1.data.associated_company_name.includes("Test Name"));

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