Skip to content

Commit ddf68fe

Browse files
fix: update types toMatch*Snapshot methods (#1097)
* fix: update types toMatch*Snapshot methods * chore: add changeset
1 parent cb15f37 commit ddf68fe

3 files changed

Lines changed: 42 additions & 21 deletions

File tree

.changeset/tasty-forks-wonder.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@wdio/visual-service": patch
3+
---
4+
5+
# 🐛 Bugfixes
6+
7+
## #1084 expect(...).toMatch*Snapshot methods do not have Promise return types
8+
9+
The methods should be typed as promises
10+
11+
# Committers: 1
12+
13+
- Wim Selles ([@wswebcreation](https://github.com/wswebcreation))

packages/visual-service/src/index.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ declare global {
112112
*/
113113
toMatchScreenSnapshot(
114114
tag: string,
115-
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
115+
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
116116
options?: WdioCheckScreenMethodOptions
117-
): R
117+
): Promise<R>
118118
toMatchScreenSnapshot(
119119
tag: string,
120120
options?: WdioCheckScreenMethodOptions
121-
): R
121+
): Promise<R>
122122
/**
123123
* Checks that if the full page screenshot matches with snapshot of baseline.
124124
* @param tag snapshot name
@@ -127,13 +127,13 @@ declare global {
127127
*/
128128
toMatchFullPageSnapshot(
129129
tag: string,
130-
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
130+
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
131131
options?: WdioCheckFullPageMethodOptions
132-
): R
132+
): Promise<R>
133133
toMatchFullPageSnapshot(
134134
tag: string,
135135
options?: WdioCheckFullPageMethodOptions
136-
): R
136+
): Promise<R>
137137
/**
138138
* Checks that if given element matches with snapshot of baseline.
139139
* @param tag snapshot name
@@ -142,13 +142,13 @@ declare global {
142142
*/
143143
toMatchElementSnapshot(
144144
tag: string,
145-
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
145+
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
146146
options?: WdioCheckElementMethodOptions
147-
): R
147+
): Promise<R>
148148
toMatchElementSnapshot(
149149
tag: string,
150150
options?: WdioCheckElementMethodOptions
151-
): R
151+
): Promise<R>
152152
/**
153153
* Checks that if the full page screenshot including tab marks matches with snapshot of baseline.
154154
* @param tag snapshot name
@@ -157,17 +157,25 @@ declare global {
157157
*/
158158
toMatchTabbablePageSnapshot(
159159
tag: string,
160-
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
160+
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
161161
options?: WdioCheckFullPageMethodOptions
162-
): R
162+
): Promise<R>
163163
toMatchTabbablePageSnapshot(
164164
tag: string,
165165
options?: WdioCheckFullPageMethodOptions
166-
): R
166+
): Promise<R>
167167
}
168168
}
169169
}
170-
export type { VisualServiceOptions }
170+
export type {
171+
VisualServiceOptions,
172+
WdioCheckElementMethodOptions,
173+
WdioCheckScreenMethodOptions,
174+
WdioCheckFullPageMethodOptions,
175+
WdioSaveElementMethodOptions,
176+
WdioSaveScreenMethodOptions,
177+
WdioSaveFullPageMethodOptions
178+
}
171179

172180
export default WdioImageComparisonService
173181
export const launcher = VisualLauncher

packages/visual-service/src/matcher.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const asymmetricMatcher =
1414
? Symbol.for('jest.asymmetricMatcher')
1515
: 0x13_57_a5
1616

17-
function isAsymmetricMatcher (expected: unknown): expected is ExpectWebdriverIO.PartialMatcher {
17+
function isAsymmetricMatcher (expected: unknown): expected is ExpectWebdriverIO.PartialMatcher<number> {
1818
return Boolean(expected && typeof expected === 'object' && '$$typeof' in expected && expected.$$typeof === asymmetricMatcher && 'asymmetricMatch' in expected)
1919
}
2020
function evaluateResult(
2121
result: ImageCompareResult,
22-
expected: number | ExpectWebdriverIO.PartialMatcher,
22+
expected: number | ExpectWebdriverIO.PartialMatcher<number>,
2323
instanceName: string
2424
) {
2525
if (isAsymmetricMatcher(expected)) {
@@ -58,7 +58,7 @@ function isMultiremoteResult(
5858
return typeof result === 'object' && Object.values(result)[0]?.misMatchPercentage !== undefined
5959
}
6060

61-
function compareResult (result: ImageCompareResult, expected: number | ExpectWebdriverIO.PartialMatcher) {
61+
function compareResult (result: ImageCompareResult, expected: number | ExpectWebdriverIO.PartialMatcher<number>) {
6262
const isMultiremote = isMultiremoteResult(result)
6363
const results = isMultiremote
6464
? Object.entries(result as unknown as Record<string, ImageCompareResult>).map(([instanceName, instanceResult]) => ({
@@ -86,7 +86,7 @@ function compareResult (result: ImageCompareResult, expected: number | ExpectWeb
8686

8787
function parseMatcherParams (
8888
tag: string,
89-
expectedResult?: number | ExpectWebdriverIO.PartialMatcher,
89+
expectedResult?: number | ExpectWebdriverIO.PartialMatcher<number>,
9090
options?: WdioCheckFullPageMethodOptions
9191
) {
9292
/**
@@ -125,7 +125,7 @@ function parseMatcherParams (
125125
export async function toMatchScreenSnapshot (
126126
browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
127127
tag: string,
128-
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
128+
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
129129
optionsOrUndefined?: WdioCheckScreenMethodOptions
130130
) {
131131
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)
@@ -136,7 +136,7 @@ export async function toMatchScreenSnapshot (
136136
export async function toMatchFullPageSnapshot (
137137
browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
138138
tag: string,
139-
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
139+
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
140140
optionsOrUndefined?: WdioCheckFullPageMethodOptions
141141
) {
142142
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)
@@ -147,7 +147,7 @@ export async function toMatchFullPageSnapshot (
147147
export async function toMatchElementSnapshot (
148148
element: WebdriverIO.Element,
149149
tag: string,
150-
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
150+
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
151151
optionsOrUndefined?: WdioCheckElementMethodOptions
152152
) {
153153
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)
@@ -159,7 +159,7 @@ export async function toMatchElementSnapshot (
159159
export async function toMatchTabbablePageSnapshot (
160160
browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser,
161161
tag: string,
162-
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher,
162+
expectedResultOrOptions?: number | ExpectWebdriverIO.PartialMatcher<number>,
163163
optionsOrUndefined?: WdioCheckFullPageMethodOptions
164164
) {
165165
const { expectedResult, options } = parseMatcherParams(tag, expectedResultOrOptions, optionsOrUndefined)

0 commit comments

Comments
 (0)