Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix: cypress findByTestId and percySnapshotElement do not work to…
Browse files Browse the repository at this point in the history
…gether (#10947)

* check for testid in percySnapshotElement

* Update percy.ts

---------

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
Kerry and t3chguy committed Jul 14, 2023
1 parent 63bdd84 commit eced103
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cypress/support/percy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ Cypress.Commands.add("percySnapshotElement", { prevSubject: "element" }, (subjec
// Await inline spinners to vanish
cy.get(".mx_InlineSpinner", { log: false }).should("not.exist");
}

let selector = subject.selector;
// cy.findByTestId sets the selector to `findByTestId(<testId>)`
// which is not usable as a scope
if (selector.startsWith("findByTestId")) {
selector = `[data-testid="${subject.attr("data-testid")}"]`;
}
cy.percySnapshot(name, {
domTransformation: (documentClone) => scope(documentClone, subject.selector),
domTransformation: (documentClone) => scope(documentClone, selector),
...options,
});
});
Expand Down

0 comments on commit eced103

Please sign in to comment.