testing-library / testcafe-testing-library

:ox: Simple and complete custom Selectors for Testcafe that encourage good testing practices.
http://npm.im/@testing-library/testcafe
MIT License
71 stars 15 forks source link

Property 'exists' does not exist on type 'NodeSnapshot'. #332

Open AdrienLemaire opened 2 years ago

AdrienLemaire commented 2 years ago

Describe the bug Following the documentation, I tried to write the following test

const main = Selector('main[role="main"]');
const dialog = Selector('div[role="dialog"]');

signin = within(main).queryByText("Sign in");
google = within(dialog).queryByText(/Google/i);

test("user clicks the sign-in button", async (t) => {
  await t
    .expect(google.exists)
    .notOk("Modal should not be opened")
    .takeScreenshot()
    .click(signin)
    .expect(google.exists)
    .ok("Modal is opened")
    .takeScreenshot();
}

When running tests, I get the following error pointing on the notOk line

   1) An error occurred in Selector code:

      TypeError: Expected container to be an Element, a Document or a DocumentFragment but
      got undefined.

And when trying to console.log the value of await googe.exists, I get

ERROR Cannot prepare tests due to the following error:

Error: TypeScript compilation failed.
/path/to/e2e/signin.ts (7, 27): Property 'exists' does not exist on type 'NodeSnapshot'.

Expected behavior

I thought from reading the examples that @testing-library/testcafe queries would return a TestCafe Selector object, making properties like exists available.

Here's a working test without using testing-library

  const main = Selector('main[role="main"]');
  const dialog = Selector('div[role="dialog"]');

  const signin = main.find("button").withText("Sign in");
  const google = dialog.find("button").withText("Google");

  await t
    .expect(google.exists)
    .notOk("Modal should not be opened")
    .takeScreenshot()
    .click(signin)
    .expect(google.exists)
    .ok("Modal is opened")
    .takeScreenshot();
benmonro commented 2 years ago

would welcome a PR if you want to take a stab at fixing this. :)