我正在尝试使用 TestCafe 在 React 网站上实现测试。我想使用 getReact() 打印各种 Prop /属性。但是,当打印到控制台时,我总是得到 ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }
。
这是我的代码:
var sideBar = ReactSelector('Sidebar').getReact();
console.log(sideBar);
我也尝试过获得实际属性(property):
sideBarprops = checkListPage.sideBar.getReact(({ props }) => props.isChecklistVisible);
console.log(sideBar);
任一项目始终打印 ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }
我需要能够打印 ReactSelector 的属性、类名、状态、键等的实际值。
最佳答案
getReact()
返回一个 Promise,您需要解析它。您可以这样做
ReactSelector('Sidebar').getReact().then(props => {
console.log(props);
})
或者这个
var sideBar = ReactSelector('Sidebar').getReact();
console.log(await sideBar);
或者这个
var sideBar = await ReactSelector('Sidebar').getReact();
console.log(sideBar);
关于reactjs - 使用 ReactSelector for TestCafe 时不断收到 `ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56669302/