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

Commit eced103

Browse files
Kerryt3chguy
Kerry
andauthored
Fix: cypress findByTestId and percySnapshotElement do not work together (#10947)
* check for testid in percySnapshotElement * Update percy.ts --------- Co-authored-by: Michael Telatynski <[email protected]>
1 parent 63bdd84 commit eced103

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cypress/support/percy.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ Cypress.Commands.add("percySnapshotElement", { prevSubject: "element" }, (subjec
4747
// Await inline spinners to vanish
4848
cy.get(".mx_InlineSpinner", { log: false }).should("not.exist");
4949
}
50+
51+
let selector = subject.selector;
52+
// cy.findByTestId sets the selector to `findByTestId(<testId>)`
53+
// which is not usable as a scope
54+
if (selector.startsWith("findByTestId")) {
55+
selector = `[data-testid="${subject.attr("data-testid")}"]`;
56+
}
5057
cy.percySnapshot(name, {
51-
domTransformation: (documentClone) => scope(documentClone, subject.selector),
58+
domTransformation: (documentClone) => scope(documentClone, selector),
5259
...options,
5360
});
5461
});

0 commit comments

Comments
 (0)