0

Let's say I have this in a test:

await t.expect(Selector('input')).ok()

And I would like to have (something like) this:

let func = 'ok';
await t.expect(Selector('input'))[func]()

This is so that I can have a map from selector to function, in order to iterate over it and check whether some elements are in the page (ok) and some not (notOk).

My above attempt does not work and returns with an interesting error:

  code: 'E1035',
  data: [
    'SyntaxError: test.js: await is a reserved word (325:14)'
  ]

I believe this is because Testcafe is doing some magic under the hood.

What would be the correct syntax to make it work?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
soquel
  • 89
  • 3

1 Answers1

2

It seems that you skipped the Selector property that you want to check (e.g. exists, visible, textContent, etc.). The following test example works properly with TestCafe v1.14.2:

import { Selector } from 'testcafe';

fixture`A set of examples that illustrate how to use TestCafe API`
    .page`http://devexpress.github.io/testcafe/example/`;


const developerName = Selector('#developer-name');
const submitButton = Selector('#submit-button');

test('New Test', async t => {
    await t
        .typeText(developerName, 'Peter Parker')
        .click(submitButton);

    let assertFunc = 'ok';
    await t.expect(Selector('#article-header').exists)[assertFunc]();
});
Dmitry Ostashev
  • 2,305
  • 1
  • 5
  • 21