Skip to content

Commit c488c6a

Browse files
committed
chore: add extra UI test
1 parent 70c473e commit c488c6a

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

tests/specs/matcher.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/// <reference types="@wdio/visual-service" />
1+
import { readdirSync } from 'node:fs'
2+
import { join } from 'node:path'
23
import { browser, expect } from '@wdio/globals'
34

45
describe('@wdio/visual-service matcher', () => {
@@ -36,4 +37,36 @@ describe('@wdio/visual-service matcher', () => {
3637
]
3738
})
3839
})
40+
41+
it(`should NOT save actual image when mismatch is within threshold (#1111) for '${browserName}'`, async () => {
42+
const tag = 'threshold-test-1111'
43+
const actualFolder = join(process.cwd(), '.tmp/actual')
44+
const subtitle = await $('.hero__subtitle')
45+
const getActualImageCount = () => {
46+
try {
47+
return readdirSync(actualFolder).filter(f => f.includes(tag)).length
48+
} catch {
49+
return 0
50+
}
51+
}
52+
53+
// 1. Save the original subtitle as baseline
54+
await browser.saveElement(subtitle, tag)
55+
56+
// 2. Manipulate the subtitle to create a small text difference
57+
await browser.execute(
58+
'arguments[0].innerHTML = "Test Demo Page";',
59+
subtitle
60+
)
61+
62+
const beforeCount = getActualImageCount()
63+
64+
// 3. Run the matcher with a threshold (90%) higher than the expected mismatch
65+
await expect(subtitle).toMatchElementSnapshot(tag, 90)
66+
67+
const afterCount = getActualImageCount()
68+
69+
// 4. With the fix: no new actual image should be saved when mismatch is within threshold
70+
expect(afterCount).toBe(beforeCount)
71+
})
3972
})

0 commit comments

Comments
 (0)