Skip to content

Commit e833a6a

Browse files
committed
refactor(browser): get test name from task in toMatchScreenshot
1 parent 9ca74cf commit e833a6a

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

packages/browser/src/client/tester/expect/toMatchScreenshot.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export default async function toMatchScreenshot(
2121
throw new Error('\'toMatchScreenshot\' cannot be used with "not"')
2222
}
2323

24-
if (this.task === undefined || this.currentTestName === undefined) {
24+
if (this.task === undefined) {
2525
throw new Error('\'toMatchScreenshot\' cannot be used without test context')
2626
}
2727

28-
const counterName = `${this.task.result?.repeatCount ?? 0}${this.testPath}${this.currentTestName}`
28+
const counterName = `${this.task.result?.repeatCount ?? 0}${this.testPath}${this.task.fullTestName}`
2929
let counter = counters.get(counterName)
3030

3131
if (counter === undefined) {
@@ -38,7 +38,7 @@ export default async function toMatchScreenshot(
3838

3939
const name = typeof nameOrOptions === 'string'
4040
? nameOrOptions
41-
: `${this.currentTestName} ${counter.current}`
41+
: `${this.task.fullTestName} ${counter.current}`
4242

4343
const normalizedOptions: Omit<ScreenshotMatcherArguments[2], 'element'> = (
4444
options.screenshotOptions && 'mask' in options.screenshotOptions
@@ -58,7 +58,7 @@ export default async function toMatchScreenshot(
5858
'__vitest_screenshotMatcher',
5959
[
6060
name,
61-
this.currentTestName,
61+
this.task.fullTestName,
6262
{
6363
element: convertToSelector(actual),
6464
...normalizedOptions,

0 commit comments

Comments
 (0)