import { expect, test } from "bun:test" type ScreenshotMatcher = { toMatchScreenshot: (name: string) => Promise | unknown } function isScreenshotMatcher(value: unknown): value is ScreenshotMatcher { return typeof value === "object" && value !== null && "toMatchScreenshot" in value && typeof (value as ScreenshotMatcher).toMatchScreenshot === "function" } const matcherProbe = expect({}) as unknown const hasScreenshotMatcher = isScreenshotMatcher(matcherProbe) const testFn = hasScreenshotMatcher ? test : test.skip testFn("CTA button snapshot", async () => { const html = `
` document.body.innerHTML = html const ctaButton = document.querySelector("[data-testid='cta']") expect(ctaButton).toBeTruthy() const bodyExpectation = expect(document.body) as unknown if (isScreenshotMatcher(bodyExpectation)) { await bodyExpectation.toMatchScreenshot("cta-button") } })