forked from webdriverio/expect-webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoHaveStyle.ts
More file actions
55 lines (45 loc) · 1.55 KB
/
toHaveStyle.ts
File metadata and controls
55 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { DEFAULT_OPTIONS } from '../../constants.js'
import type { WdioElementMaybePromise } from '../../types.js'
import {
compareStyle,
enhanceError,
executeCommand,
waitUntil,
wrapExpectedWithArray
} from '../../utils.js'
async function condition(el: WebdriverIO.Element, style: { [key: string]: string; }, options: ExpectWebdriverIO.StringOptions) {
return compareStyle(el, style, options)
}
export async function toHaveStyle(
received: WdioElementMaybePromise,
expectedValue: { [key: string]: string; },
options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS
) {
const isNot = this.isNot
const { expectation = 'style', verb = 'have' } = this
await options.beforeAssertion?.({
matcherName: 'toHaveStyle',
expectedValue,
options,
})
let el = await received?.getElement()
let actualStyle
const pass = await waitUntil(async () => {
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options])
el = result.el as WebdriverIO.Element
actualStyle = result.values
return result.success
}, isNot, options)
const message = enhanceError(el, wrapExpectedWithArray(el, actualStyle, expectedValue), actualStyle, this, verb, expectation, '', options)
const result: ExpectWebdriverIO.AssertionResult = {
pass,
message: (): string => message
}
await options.afterAssertion?.({
matcherName: 'toHaveStyle',
expectedValue,
options,
result
})
return result
}