Search code examples
reactjsautomated-testse2e-testingweb-testingtestcafe

Keep getting `ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }` when using ReactSelector for TestCafe


I am trying to implement testing on a React website using TestCafe. I want to print the various props/attributes using getReact(). However, when printing to the console, I always get ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null } instead.

Here is my code:

var sideBar = ReactSelector('Sidebar').getReact();
console.log(sideBar);

I've also tried to get an actual property:

sideBarprops = checkListPage.sideBar.getReact(({ props }) => props.isChecklistVisible);
console.log(sideBar);

Either item always prints ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }

I need to be able to print the actual values of properties, classNames, state, Keys, etc of a ReactSelector.


Solution

  • getReact() return a Promise, which you need to resolve. You can either do this

    ReactSelector('Sidebar').getReact().then(props => {
       console.log(props);
    })
    

    or this

    var sideBar = ReactSelector('Sidebar').getReact();
    console.log(await sideBar);
    

    or this

    var sideBar = await ReactSelector('Sidebar').getReact();
    console.log(sideBar);