DEV Community

Discussion on: React Specific Selectors in TestCafe

Collapse
 
tallku profile image
Tall-KU

This is really beneficial! Coming from a beginner in React though, I am finding it difficult to really utilize the React plugin for TestCafe.

Maybe the website I'm having to test isn't really following React principals, but how do you print properties, state, keys, etc. from React? I want to print stuff to the console, but get this: ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }

Collapse
 
mwoodson profile image
marques woodson

Where are you doing the console.log? In the React component, or in your test?

Collapse
 
tallku profile image
Tall-KU

no, it is within the TestCafe fixture/test



test.only('testing', async t => {
    var doubleArrowLeft = ReactSelector('Button').withProps({Key : 'fal fa-chevron-double-left'});
    console.log(doubleArrowLeft.getReact())
    await t.expect(doubleArrowLeft).eql(true);
})
Thread Thread
 
mwoodson profile image
marques woodson

doubleArrowLeft.getReact() returns a promise. So try this:

var doubleArrowLeft = ReactSelector('Button').withProps(
  { Key : 'fal fa-chevron-double-left' }
);
const doubleArrowLeftData = await doubleArrowLeft.getReact();
console.log(doubleArrowLeftData)
Thread Thread
 
tallku profile image
Tall-KU

That didn't work....

Thread Thread
 
mwoodson profile image
marques woodson

Here's what I tested really quick:

fixture("A fixture this is").page("http://localhost:3002");

test("this is a test", async t => {
  const header = ReactSelector("Header").withProps({ name: "marques" });
  const stuff = await header.getReact();
  console.log(stuff);
});

outputs:

$ testcafe chrome:headless test.ts
 Running tests in:
 - HeadlessChrome 74.0.3729 / Mac OS X 10.14.5

 A fixture this is
{ state: {}, props: { name: 'marques' }, key: null }
 ✓ this is a test

Try this out

Thread Thread
 
tallku profile image
Tall-KU

Awesome, thanks for the help. So, I figured out my issue. I was trying to locate the selector by 'Key', which is NOT a property!

Thread Thread
 
mwoodson profile image
marques woodson

Aaah yea, you'd want to use withKey instead of withProps. I'm glad you got it figured out :)