From 8c007fd3fc177f748ef4345291d05083d6446f90 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 5 Feb 2024 22:52:16 +0100 Subject: [PATCH] fix(toHaveScreenshot): stylePath as first arg (#29372) --- packages/playwright/src/matchers/toMatchSnapshot.ts | 2 +- tests/playwright-test/to-have-screenshot.spec.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/playwright/src/matchers/toMatchSnapshot.ts b/packages/playwright/src/matchers/toMatchSnapshot.ts index f65b324095..0a913b24dd 100644 --- a/packages/playwright/src/matchers/toMatchSnapshot.ts +++ b/packages/playwright/src/matchers/toMatchSnapshot.ts @@ -351,7 +351,7 @@ export async function toHaveScreenshot( expectTypes(pageOrLocator, ['Page', 'Locator'], 'toHaveScreenshot'); return await zones.preserve(async () => { // Loading from filesystem resets zones. - const style = await loadScreenshotStyles(optOptions.stylePath || config?.stylePath); + const style = await loadScreenshotStyles(helper.allOptions.stylePath || config?.stylePath); return toHaveScreenshotContinuation.call(this, helper, page, locator, config, style); }); } diff --git a/tests/playwright-test/to-have-screenshot.spec.ts b/tests/playwright-test/to-have-screenshot.spec.ts index ef07b58090..95a95e4cb1 100644 --- a/tests/playwright-test/to-have-screenshot.spec.ts +++ b/tests/playwright-test/to-have-screenshot.spec.ts @@ -1272,6 +1272,7 @@ test('should support stylePath option', async ({ runInlineTest }) => { snapshotPathTemplate: '__screenshots__/{testFilePath}/{arg}{ext}', }), '__screenshots__/tests/a.spec.js/snapshot.png': createImage(IMG_WIDTH, IMG_HEIGHT, 0, 255, 0), + '__screenshots__/tests/a.spec.js/png-1.png': createImage(IMG_WIDTH, IMG_HEIGHT, 0, 255, 0), 'screenshot.css': 'body { background: #00FF00; }', 'tests/a.spec.js': ` const { test, expect } = require('@playwright/test'); @@ -1280,6 +1281,9 @@ test('should support stylePath option', async ({ runInlineTest }) => { await expect(page).toHaveScreenshot('snapshot.png', { stylePath: './screenshot.css', }); + await expect(page).toHaveScreenshot({ + stylePath: './screenshot.css', + }); }); `, });