Skip to content

Commit 4d03866

Browse files
authored
feat: add title option to matchImage command (#81)
added option to override title added example update README.md
1 parent 2c6c41e commit 4d03866

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ cy.matchImage({
160160
// helps with screenshots being scaled 2x on high-density screens like Mac Retina
161161
// default: true
162162
forceDeviceScaleFactor: false,
163+
// title used for naming the image file
164+
// default: Cypress.currentTest.titlePath (your test title)
165+
title: `${Cypress.currentTest.titlePath.join(' ')} (${Cypress.browser.displayName})`
163166
})
164167
```
165168

src/commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare global {
1010
updateImages?: boolean;
1111
imagesDir?: string;
1212
maxDiffThreshold?: number;
13+
title?: string;
1314
};
1415

1516
interface Chainable<Subject> {
@@ -30,7 +31,7 @@ Cypress.Commands.add(
3031
{ prevSubject: "optional" },
3132
(subject, options = {}) => {
3233
const $el = subject as JQuery<HTMLElement> | undefined;
33-
let title = Cypress.currentTest.titlePath.join(" ");
34+
let title = options.title || Cypress.currentTest.titlePath.join(" ");
3435
if (typeof nameCacheCounter[title] === "undefined")
3536
nameCacheCounter[title] = -1;
3637
title += ` #${++nameCacheCounter[title]}`;

0 commit comments

Comments
 (0)