expect-webdriverio 5.3.2 → 5.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/test/__fixtures__/utils.js +19 -0
- package/lib/test/index.test.js +8 -0
- package/lib/test/matchers/beMatchers.test.js +109 -0
- package/lib/test/matchers/browser/toHaveClipboardText.test.js +21 -0
- package/lib/test/matchers/browserMatchers.test.js +102 -0
- package/lib/test/matchers/element/toBeDisabled.test.js +121 -0
- package/lib/test/matchers/element/toHaveAttribute.test.js +131 -0
- package/lib/test/matchers/element/toHaveChildren.test.js +62 -0
- package/lib/test/matchers/element/toHaveComputedLabel.test.js +284 -0
- package/lib/test/matchers/element/toHaveComputedRole.test.js +284 -0
- package/lib/test/matchers/element/toHaveElementClass.test.js +125 -0
- package/lib/test/matchers/element/toHaveElementProperty.test.js +111 -0
- package/lib/test/matchers/element/toHaveHTML.test.js +291 -0
- package/lib/test/matchers/element/toHaveHeight.test.js +171 -0
- package/lib/test/matchers/element/toHaveHref.test.js +54 -0
- package/lib/test/matchers/element/toHaveId.test.js +54 -0
- package/lib/test/matchers/element/toHaveSize.test.js +109 -0
- package/lib/test/matchers/element/toHaveStyle.test.js +199 -0
- package/lib/test/matchers/element/toHaveText.test.js +333 -0
- package/lib/test/matchers/element/toHaveValue.test.js +81 -0
- package/lib/test/matchers/element/toHaveWidth.test.js +171 -0
- package/lib/test/matchers/elements/toBeElementsArrayOfSize.test.js +141 -0
- package/lib/test/matchers/mock/toBeRequested.test.js +73 -0
- package/lib/test/matchers/mock/toBeRequestedTimes.test.js +108 -0
- package/lib/test/matchers/mock/toBeRequestedWith.test.js +343 -0
- package/lib/test/matchers.test.js +54 -0
- package/lib/test/snapshot.test.js +53 -0
- package/lib/test/softAssertions.test.js +332 -0
- package/lib/test/util/elementsUtil.test.js +18 -0
- package/lib/test/util/formatMessage.test.js +96 -0
- package/lib/test/util/refetchElements.test.js +19 -0
- package/lib/test/utils.test.js +117 -0
- package/lib/{tsconfig.build.tsbuildinfo → tsconfig.tsbuildinfo} +1 -1
- package/package.json +2 -2
- package/types/expect-webdriverio.d.ts +39 -28
- package/types/standalone.d.ts +2 -0
- /package/lib/{constants.js → src/constants.js} +0 -0
- /package/lib/{index.js → src/index.js} +0 -0
- /package/lib/{jasmineUtils.js → src/jasmineUtils.js} +0 -0
- /package/lib/{matchers → src/matchers}/browser/toHaveClipboardText.js +0 -0
- /package/lib/{matchers → src/matchers}/browser/toHaveTitle.js +0 -0
- /package/lib/{matchers → src/matchers}/browser/toHaveUrl.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeClickable.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeDisabled.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeDisplayed.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeDisplayedInViewport.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeEnabled.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeExisting.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeFocused.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toBeSelected.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveAttribute.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveChildren.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveClass.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveComputedLabel.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveComputedRole.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveElementProperty.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveHTML.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveHeight.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveHref.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveId.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveSize.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveStyle.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveText.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveValue.js +0 -0
- /package/lib/{matchers → src/matchers}/element/toHaveWidth.js +0 -0
- /package/lib/{matchers → src/matchers}/elements/toBeElementsArrayOfSize.js +0 -0
- /package/lib/{matchers → src/matchers}/mock/toBeRequested.js +0 -0
- /package/lib/{matchers → src/matchers}/mock/toBeRequestedTimes.js +0 -0
- /package/lib/{matchers → src/matchers}/mock/toBeRequestedWith.js +0 -0
- /package/lib/{matchers → src/matchers}/snapshot.js +0 -0
- /package/lib/{matchers.js → src/matchers.js} +0 -0
- /package/lib/{snapshot.js → src/snapshot.js} +0 -0
- /package/lib/{softAssert.js → src/softAssert.js} +0 -0
- /package/lib/{softAssertService.js → src/softAssertService.js} +0 -0
- /package/lib/{softExpect.js → src/softExpect.js} +0 -0
- /package/lib/{types.js → src/types.js} +0 -0
- /package/lib/{util → src/util}/elementsUtil.js +0 -0
- /package/lib/{util → src/util}/executeCommand.js +0 -0
- /package/lib/{util → src/util}/formatMessage.js +0 -0
- /package/lib/{util → src/util}/refetchElements.js +0 -0
- /package/lib/{utils.js → src/utils.js} +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { vi, test, describe, expect } from 'vitest';
|
|
2
|
+
import { $ } from '@wdio/globals';
|
|
3
|
+
import { getExpectMessage, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveHeight } from '../../../src/matchers/element/toHaveHeight.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveHeight', () => {
|
|
7
|
+
test('wait for success', async () => {
|
|
8
|
+
const el = await $('sel');
|
|
9
|
+
el._attempts = 2;
|
|
10
|
+
el._size = function (property) {
|
|
11
|
+
if (this._attempts > 0) {
|
|
12
|
+
this._attempts--;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
if (property === 'width') {
|
|
16
|
+
return 50;
|
|
17
|
+
}
|
|
18
|
+
if (property === 'height') {
|
|
19
|
+
return 32;
|
|
20
|
+
}
|
|
21
|
+
return { width: 50, height: 32 };
|
|
22
|
+
};
|
|
23
|
+
const beforeAssertion = vi.fn();
|
|
24
|
+
const afterAssertion = vi.fn();
|
|
25
|
+
const result = await toHaveHeight.call({}, el, 32, { beforeAssertion, afterAssertion });
|
|
26
|
+
expect(result.pass).toBe(true);
|
|
27
|
+
expect(el._attempts).toBe(0);
|
|
28
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
29
|
+
matcherName: 'toHaveHeight',
|
|
30
|
+
expectedValue: 32,
|
|
31
|
+
options: { beforeAssertion, afterAssertion }
|
|
32
|
+
});
|
|
33
|
+
expect(afterAssertion).toBeCalledWith({
|
|
34
|
+
matcherName: 'toHaveHeight',
|
|
35
|
+
expectedValue: 32,
|
|
36
|
+
options: { beforeAssertion, afterAssertion },
|
|
37
|
+
result
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
test('wait but failure', async () => {
|
|
41
|
+
const el = await $('sel');
|
|
42
|
+
el._size = function () {
|
|
43
|
+
throw new Error('some error');
|
|
44
|
+
};
|
|
45
|
+
await expect(() => toHaveHeight.call({}, el, 10, {}))
|
|
46
|
+
.rejects.toThrow('some error');
|
|
47
|
+
});
|
|
48
|
+
test('success on the first attempt', async () => {
|
|
49
|
+
const el = await $('sel');
|
|
50
|
+
el._attempts = 0;
|
|
51
|
+
el._size = function (property) {
|
|
52
|
+
this._attempts++;
|
|
53
|
+
if (property === 'width') {
|
|
54
|
+
return 50;
|
|
55
|
+
}
|
|
56
|
+
if (property === 'height') {
|
|
57
|
+
return 32;
|
|
58
|
+
}
|
|
59
|
+
return { width: 50, height: 32 };
|
|
60
|
+
};
|
|
61
|
+
const result = await toHaveHeight.call({}, el, 32, {});
|
|
62
|
+
expect(result.message()).toEqual('Expect $(`sel`) to have height\n\nExpected: 32\nReceived: serializes to the same string');
|
|
63
|
+
expect(result.pass).toBe(true);
|
|
64
|
+
expect(el._attempts).toBe(1);
|
|
65
|
+
});
|
|
66
|
+
test('no wait - failure', async () => {
|
|
67
|
+
const el = await $('sel');
|
|
68
|
+
el._attempts = 0;
|
|
69
|
+
el._size = function (property) {
|
|
70
|
+
this._attempts++;
|
|
71
|
+
if (property === 'width') {
|
|
72
|
+
return 50;
|
|
73
|
+
}
|
|
74
|
+
if (property === 'height') {
|
|
75
|
+
return 32;
|
|
76
|
+
}
|
|
77
|
+
return { width: 50, height: 32 };
|
|
78
|
+
};
|
|
79
|
+
const result = await toHaveHeight.call({}, el, 10, { wait: 0 });
|
|
80
|
+
expect(result.message()).toEqual('Expect $(`sel`) to have height\n\nExpected: 10\nReceived: 32');
|
|
81
|
+
expect(result.pass).toBe(false);
|
|
82
|
+
expect(el._attempts).toBe(1);
|
|
83
|
+
});
|
|
84
|
+
test('no wait - success', async () => {
|
|
85
|
+
const el = await $('sel');
|
|
86
|
+
el._attempts = 0;
|
|
87
|
+
el._size = function (property) {
|
|
88
|
+
this._attempts++;
|
|
89
|
+
if (property === 'width') {
|
|
90
|
+
return 50;
|
|
91
|
+
}
|
|
92
|
+
if (property === 'height') {
|
|
93
|
+
return 32;
|
|
94
|
+
}
|
|
95
|
+
return { width: 50, height: 32 };
|
|
96
|
+
};
|
|
97
|
+
const result = await toHaveHeight.call({}, el, 32, { wait: 0 });
|
|
98
|
+
expect(result.pass).toBe(true);
|
|
99
|
+
expect(el._attempts).toBe(1);
|
|
100
|
+
});
|
|
101
|
+
test('gte and lte', async () => {
|
|
102
|
+
const el = await $('sel');
|
|
103
|
+
el._attempts = 0;
|
|
104
|
+
el._size = function (property) {
|
|
105
|
+
this._attempts++;
|
|
106
|
+
if (property === 'width') {
|
|
107
|
+
return 50;
|
|
108
|
+
}
|
|
109
|
+
if (property === 'height') {
|
|
110
|
+
return 32;
|
|
111
|
+
}
|
|
112
|
+
return { width: 50, height: 32 };
|
|
113
|
+
};
|
|
114
|
+
const result = await toHaveHeight.call({}, el, { gte: 31, lte: 33 }, { wait: 0 });
|
|
115
|
+
expect(result.message()).toEqual('Expect $(`sel`) to have height\n\nExpected: ">= 31 && <= 33"\nReceived: 32');
|
|
116
|
+
expect(result.pass).toBe(true);
|
|
117
|
+
expect(el._attempts).toBe(1);
|
|
118
|
+
});
|
|
119
|
+
test('not - failure', async () => {
|
|
120
|
+
const el = await $('sel');
|
|
121
|
+
el._size = function (property) {
|
|
122
|
+
if (property === 'width') {
|
|
123
|
+
return 50;
|
|
124
|
+
}
|
|
125
|
+
if (property === 'height') {
|
|
126
|
+
return 32;
|
|
127
|
+
}
|
|
128
|
+
return { width: 50, height: 32 };
|
|
129
|
+
};
|
|
130
|
+
const result = await toHaveHeight.call({}, el, 32, { wait: 0 });
|
|
131
|
+
const received = getReceived(result.message());
|
|
132
|
+
expect(received).not.toContain('not');
|
|
133
|
+
expect(result.pass).toBe(true);
|
|
134
|
+
});
|
|
135
|
+
test("should return false if sizes don't match", async () => {
|
|
136
|
+
const el = await $('sel');
|
|
137
|
+
el._size = function (property) {
|
|
138
|
+
if (property === 'width') {
|
|
139
|
+
return 50;
|
|
140
|
+
}
|
|
141
|
+
if (property === 'height') {
|
|
142
|
+
return 32;
|
|
143
|
+
}
|
|
144
|
+
return { width: 50, height: 32 };
|
|
145
|
+
};
|
|
146
|
+
const result = await toHaveHeight.bind({})(el, 10, { wait: 1 });
|
|
147
|
+
expect(result.pass).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
test('should return true if sizes match', async () => {
|
|
150
|
+
const el = await $('sel');
|
|
151
|
+
el._size = function (property) {
|
|
152
|
+
if (property === 'width') {
|
|
153
|
+
return 50;
|
|
154
|
+
}
|
|
155
|
+
if (property === 'height') {
|
|
156
|
+
return 32;
|
|
157
|
+
}
|
|
158
|
+
return { width: 50, height: 32 };
|
|
159
|
+
};
|
|
160
|
+
const result = await toHaveHeight.bind({})(el, 32, { wait: 1 });
|
|
161
|
+
expect(result.pass).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
test('message', async () => {
|
|
164
|
+
const el = await $('sel');
|
|
165
|
+
el._size = function () {
|
|
166
|
+
return null;
|
|
167
|
+
};
|
|
168
|
+
const result = await toHaveHeight.call({}, el, 50);
|
|
169
|
+
expect(getExpectMessage(result.message())).toContain('to have height');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { vi, test, describe, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { $ } from '@wdio/globals';
|
|
3
|
+
import { getExpectMessage, getExpected, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveHref } from '../../../src/matchers/element/toHaveHref.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveHref', () => {
|
|
7
|
+
let el;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
el = await $('sel');
|
|
10
|
+
el.getAttribute = vi.fn().mockImplementation((attribute) => {
|
|
11
|
+
if (attribute === 'href') {
|
|
12
|
+
return 'https://www.example.com';
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
test('success when contains', async () => {
|
|
18
|
+
const beforeAssertion = vi.fn();
|
|
19
|
+
const afterAssertion = vi.fn();
|
|
20
|
+
const result = await toHaveHref.call({}, el, 'https://www.example.com', { beforeAssertion, afterAssertion });
|
|
21
|
+
expect(result.pass).toBe(true);
|
|
22
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
23
|
+
matcherName: 'toHaveHref',
|
|
24
|
+
expectedValue: 'https://www.example.com',
|
|
25
|
+
options: { beforeAssertion, afterAssertion }
|
|
26
|
+
});
|
|
27
|
+
expect(afterAssertion).toBeCalledWith({
|
|
28
|
+
matcherName: 'toHaveHref',
|
|
29
|
+
expectedValue: 'https://www.example.com',
|
|
30
|
+
options: { beforeAssertion, afterAssertion },
|
|
31
|
+
result
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('failure when doesnt contain', () => {
|
|
35
|
+
let result;
|
|
36
|
+
beforeEach(async () => {
|
|
37
|
+
result = await toHaveHref.call({}, el, 'an href');
|
|
38
|
+
});
|
|
39
|
+
test('failure', () => {
|
|
40
|
+
expect(result.pass).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
describe('message shows correctly', () => {
|
|
43
|
+
test('expect message', () => {
|
|
44
|
+
expect(getExpectMessage(result.message())).toContain('to have attribute href');
|
|
45
|
+
});
|
|
46
|
+
test('expected message', () => {
|
|
47
|
+
expect(getExpected(result.message())).toContain('an href');
|
|
48
|
+
});
|
|
49
|
+
test('received message', () => {
|
|
50
|
+
expect(getReceived(result.message())).toContain('https://www.example.com');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { vi, test, describe, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { $ } from '@wdio/globals';
|
|
3
|
+
import { getExpectMessage, getExpected, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveId } from '../../../src/matchers/element/toHaveId.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveId', () => {
|
|
7
|
+
let el;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
el = await $('sel');
|
|
10
|
+
el.getAttribute = vi.fn().mockImplementation((attribute) => {
|
|
11
|
+
if (attribute === 'id') {
|
|
12
|
+
return 'test id';
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
test('success', async () => {
|
|
18
|
+
const result = await toHaveId.call({}, el, 'test id');
|
|
19
|
+
expect(result.pass).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
describe('failure', () => {
|
|
22
|
+
let result;
|
|
23
|
+
const beforeAssertion = vi.fn();
|
|
24
|
+
const afterAssertion = vi.fn();
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
result = await toHaveId.call({}, el, 'an attribute', { beforeAssertion, afterAssertion });
|
|
27
|
+
});
|
|
28
|
+
test('failure', () => {
|
|
29
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
30
|
+
matcherName: 'toHaveId',
|
|
31
|
+
expectedValue: 'an attribute',
|
|
32
|
+
options: { beforeAssertion, afterAssertion }
|
|
33
|
+
});
|
|
34
|
+
expect(result.pass).toBe(false);
|
|
35
|
+
expect(afterAssertion).toBeCalledWith({
|
|
36
|
+
matcherName: 'toHaveId',
|
|
37
|
+
expectedValue: 'an attribute',
|
|
38
|
+
options: { beforeAssertion, afterAssertion },
|
|
39
|
+
result
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('message shows correctly', () => {
|
|
43
|
+
test('expect message', () => {
|
|
44
|
+
expect(getExpectMessage(result.message())).toContain('to have attribute id');
|
|
45
|
+
});
|
|
46
|
+
test('expected message', () => {
|
|
47
|
+
expect(getExpected(result.message())).toContain('an attribute');
|
|
48
|
+
});
|
|
49
|
+
test('received message', () => {
|
|
50
|
+
expect(getReceived(result.message())).toContain('test id');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { vi, test, describe, expect } from 'vitest';
|
|
2
|
+
import { $ } from '@wdio/globals';
|
|
3
|
+
import { getExpectMessage, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveSize } from '../../../src/matchers/element/toHaveSize.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveSize', () => {
|
|
7
|
+
test('wait for success', async () => {
|
|
8
|
+
const el = await $('sel');
|
|
9
|
+
el._attempts = 2;
|
|
10
|
+
el._size = function () {
|
|
11
|
+
if (this._attempts > 0) {
|
|
12
|
+
this._attempts--;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return { width: 32, height: 32 };
|
|
16
|
+
};
|
|
17
|
+
const beforeAssertion = vi.fn();
|
|
18
|
+
const afterAssertion = vi.fn();
|
|
19
|
+
const result = await toHaveSize.call({}, el, { width: 32, height: 32 }, { beforeAssertion, afterAssertion });
|
|
20
|
+
expect(result.pass).toBe(true);
|
|
21
|
+
expect(el._attempts).toBe(0);
|
|
22
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
23
|
+
matcherName: 'toHaveSize',
|
|
24
|
+
expectedValue: { width: 32, height: 32 },
|
|
25
|
+
options: { beforeAssertion, afterAssertion }
|
|
26
|
+
});
|
|
27
|
+
expect(afterAssertion).toBeCalledWith({
|
|
28
|
+
matcherName: 'toHaveSize',
|
|
29
|
+
expectedValue: { width: 32, height: 32 },
|
|
30
|
+
options: { beforeAssertion, afterAssertion },
|
|
31
|
+
result
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
test('wait but failure', async () => {
|
|
35
|
+
const el = await $('sel');
|
|
36
|
+
el._size = function () {
|
|
37
|
+
throw new Error('some error');
|
|
38
|
+
};
|
|
39
|
+
await expect(() => toHaveSize.call({}, el, { width: 32, height: 32 }, {}))
|
|
40
|
+
.rejects.toThrow('some error');
|
|
41
|
+
});
|
|
42
|
+
test('success on the first attempt', async () => {
|
|
43
|
+
const el = await $('sel');
|
|
44
|
+
el._attempts = 0;
|
|
45
|
+
el._size = function () {
|
|
46
|
+
this._attempts++;
|
|
47
|
+
return { width: 32, height: 32 };
|
|
48
|
+
};
|
|
49
|
+
const result = await toHaveSize.call({}, el, { width: 32, height: 32 }, {});
|
|
50
|
+
expect(result.pass).toBe(true);
|
|
51
|
+
expect(el._attempts).toBe(1);
|
|
52
|
+
});
|
|
53
|
+
test('no wait - failure', async () => {
|
|
54
|
+
const el = await $('sel');
|
|
55
|
+
el._attempts = 0;
|
|
56
|
+
el._size = function () {
|
|
57
|
+
this._attempts++;
|
|
58
|
+
return { width: 32, height: 32 };
|
|
59
|
+
};
|
|
60
|
+
const result = await toHaveSize.call({}, el, { width: 15, height: 32 }, { wait: 0 });
|
|
61
|
+
expect(result.pass).toBe(false);
|
|
62
|
+
expect(el._attempts).toBe(1);
|
|
63
|
+
});
|
|
64
|
+
test('no wait - success', async () => {
|
|
65
|
+
const el = await $('sel');
|
|
66
|
+
el._attempts = 0;
|
|
67
|
+
el._size = function () {
|
|
68
|
+
this._attempts++;
|
|
69
|
+
return { width: 32, height: 32 };
|
|
70
|
+
};
|
|
71
|
+
const result = await toHaveSize.call({}, el, { width: 32, height: 32 }, { wait: 0 });
|
|
72
|
+
expect(result.pass).toBe(true);
|
|
73
|
+
expect(el._attempts).toBe(1);
|
|
74
|
+
});
|
|
75
|
+
test('not - failure', async () => {
|
|
76
|
+
const el = await $('sel');
|
|
77
|
+
el._size = function () {
|
|
78
|
+
return { width: 32, height: 32 };
|
|
79
|
+
};
|
|
80
|
+
const result = await toHaveSize.call({}, el, { width: 32, height: 32 }, { wait: 0 });
|
|
81
|
+
const received = getReceived(result.message());
|
|
82
|
+
expect(received).not.toContain('not');
|
|
83
|
+
expect(result.pass).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
test("should return false if sizes don't match", async () => {
|
|
86
|
+
const el = await $('sel');
|
|
87
|
+
el._size = function () {
|
|
88
|
+
return { width: 32, height: 32 };
|
|
89
|
+
};
|
|
90
|
+
const result = await toHaveSize.bind({})(el, { width: 15, height: 32 }, { wait: 1 });
|
|
91
|
+
expect(result.pass).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
test('should return true if sizes match', async () => {
|
|
94
|
+
const el = await $('sel');
|
|
95
|
+
el._size = function () {
|
|
96
|
+
return { width: 32, height: 32 };
|
|
97
|
+
};
|
|
98
|
+
const result = await toHaveSize.bind({})(el, { width: 32, height: 32 }, { wait: 1 });
|
|
99
|
+
expect(result.pass).toBe(true);
|
|
100
|
+
});
|
|
101
|
+
test('message', async () => {
|
|
102
|
+
const el = await $('sel');
|
|
103
|
+
el._size = function () {
|
|
104
|
+
return null;
|
|
105
|
+
};
|
|
106
|
+
const result = await toHaveSize.call({}, el, { width: 32, height: 32 });
|
|
107
|
+
expect(getExpectMessage(result.message())).toContain('to have size');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { vi, test, describe, expect } from 'vitest';
|
|
2
|
+
import { $ } from '@wdio/globals';
|
|
3
|
+
import { getExpectMessage, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveStyle } from '../../../src/matchers/element/toHaveStyle.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveStyle', () => {
|
|
7
|
+
let el;
|
|
8
|
+
const mockStyle = {
|
|
9
|
+
'font-family': 'Faktum',
|
|
10
|
+
'font-size': '26px',
|
|
11
|
+
'color': '#000'
|
|
12
|
+
};
|
|
13
|
+
test('wait for success', async () => {
|
|
14
|
+
el = await $('sel');
|
|
15
|
+
el._attempts = 2;
|
|
16
|
+
let counter = 0;
|
|
17
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
18
|
+
if (el._attempts > 0) {
|
|
19
|
+
counter++;
|
|
20
|
+
if (counter === Object.keys(mockStyle).length) {
|
|
21
|
+
counter = 0;
|
|
22
|
+
el._attempts--;
|
|
23
|
+
}
|
|
24
|
+
return { value: 'Wrong Value' };
|
|
25
|
+
}
|
|
26
|
+
return { value: mockStyle[property] };
|
|
27
|
+
});
|
|
28
|
+
const beforeAssertion = vi.fn();
|
|
29
|
+
const afterAssertion = vi.fn();
|
|
30
|
+
const result = await toHaveStyle.call({}, el, mockStyle, { ignoreCase: true, beforeAssertion, afterAssertion });
|
|
31
|
+
expect(result.pass).toBe(true);
|
|
32
|
+
expect(el._attempts).toBe(0);
|
|
33
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
34
|
+
matcherName: 'toHaveStyle',
|
|
35
|
+
expectedValue: mockStyle,
|
|
36
|
+
options: { ignoreCase: true, beforeAssertion, afterAssertion }
|
|
37
|
+
});
|
|
38
|
+
expect(afterAssertion).toBeCalledWith({
|
|
39
|
+
matcherName: 'toHaveStyle',
|
|
40
|
+
expectedValue: mockStyle,
|
|
41
|
+
options: { ignoreCase: true, beforeAssertion, afterAssertion },
|
|
42
|
+
result
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
test('wait but failure', async () => {
|
|
46
|
+
el = await $('sel');
|
|
47
|
+
el._attempts = 0;
|
|
48
|
+
let counter = 0;
|
|
49
|
+
el.getCSSProperty = vi.fn().mockImplementation(() => {
|
|
50
|
+
counter++;
|
|
51
|
+
if (counter === Object.keys(mockStyle).length) {
|
|
52
|
+
counter = 0;
|
|
53
|
+
el._attempts++;
|
|
54
|
+
}
|
|
55
|
+
throw new Error('some error');
|
|
56
|
+
});
|
|
57
|
+
await expect(() => toHaveStyle.call({}, el, mockStyle, { ignoreCase: true }))
|
|
58
|
+
.rejects.toThrow('some error');
|
|
59
|
+
});
|
|
60
|
+
test('success on the first attempt', async () => {
|
|
61
|
+
const el = await $('sel');
|
|
62
|
+
el._attempts = 0;
|
|
63
|
+
let counter = 0;
|
|
64
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
65
|
+
counter++;
|
|
66
|
+
if (counter === Object.keys(mockStyle).length) {
|
|
67
|
+
counter = 0;
|
|
68
|
+
el._attempts++;
|
|
69
|
+
}
|
|
70
|
+
return { value: mockStyle[property] };
|
|
71
|
+
});
|
|
72
|
+
const result = await toHaveStyle.call({}, el, mockStyle, { ignoreCase: true });
|
|
73
|
+
expect(result.pass).toBe(true);
|
|
74
|
+
expect(el._attempts).toBe(1);
|
|
75
|
+
});
|
|
76
|
+
test('no wait - failure', async () => {
|
|
77
|
+
const el = await $('sel');
|
|
78
|
+
el._attempts = 0;
|
|
79
|
+
let counter = 0;
|
|
80
|
+
el.getCSSProperty = vi.fn().mockImplementation(() => {
|
|
81
|
+
counter++;
|
|
82
|
+
if (counter === Object.keys(mockStyle).length) {
|
|
83
|
+
counter = 0;
|
|
84
|
+
el._attempts++;
|
|
85
|
+
}
|
|
86
|
+
return { value: 'Wrong Value' };
|
|
87
|
+
});
|
|
88
|
+
const result = await toHaveStyle.call({}, el, mockStyle, { wait: 0 });
|
|
89
|
+
expect(result.pass).toBe(false);
|
|
90
|
+
expect(el._attempts).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
test('no wait - success', async () => {
|
|
93
|
+
const el = await $('sel');
|
|
94
|
+
el._attempts = 0;
|
|
95
|
+
let counter = 0;
|
|
96
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
97
|
+
counter++;
|
|
98
|
+
if (counter === Object.keys(mockStyle).length) {
|
|
99
|
+
counter = 0;
|
|
100
|
+
el._attempts++;
|
|
101
|
+
}
|
|
102
|
+
return { value: mockStyle[property] };
|
|
103
|
+
});
|
|
104
|
+
const result = await toHaveStyle.call({}, el, mockStyle, { wait: 0 });
|
|
105
|
+
expect(result.pass).toBe(true);
|
|
106
|
+
expect(el._attempts).toBe(1);
|
|
107
|
+
});
|
|
108
|
+
test('not - failure', async () => {
|
|
109
|
+
const el = await $('sel');
|
|
110
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
111
|
+
return { value: mockStyle[property] };
|
|
112
|
+
});
|
|
113
|
+
const result = await toHaveStyle.call({ isNot: true }, el, mockStyle, { wait: 0 });
|
|
114
|
+
const received = getReceived(result.message());
|
|
115
|
+
expect(received).not.toContain('not');
|
|
116
|
+
expect(result.pass).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
test('should return false if styles dont match', async () => {
|
|
119
|
+
const el = await $('sel');
|
|
120
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
121
|
+
return { value: mockStyle[property] };
|
|
122
|
+
});
|
|
123
|
+
const wrongStyle = {
|
|
124
|
+
'font-family': 'Incorrect Font',
|
|
125
|
+
'font-size': '100px',
|
|
126
|
+
'color': '#fff'
|
|
127
|
+
};
|
|
128
|
+
const result = await toHaveStyle.bind({ isNot: true })(el, wrongStyle, { wait: 1 });
|
|
129
|
+
expect(result.pass).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
test('should return true if styles match', async () => {
|
|
132
|
+
const el = await $('sel');
|
|
133
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
134
|
+
return { value: mockStyle[property] };
|
|
135
|
+
});
|
|
136
|
+
const result = await toHaveStyle.bind({ isNot: true })(el, mockStyle, { wait: 1 });
|
|
137
|
+
expect(result.pass).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
test('message shows correctly', async () => {
|
|
140
|
+
const el = await $('sel');
|
|
141
|
+
el.getCSSProperty = vi.fn().mockImplementation(() => {
|
|
142
|
+
return { value: 'Wrong Value' };
|
|
143
|
+
});
|
|
144
|
+
const result = await toHaveStyle.call({}, el, 'WebdriverIO');
|
|
145
|
+
expect(getExpectMessage(result.message())).toContain('to have style');
|
|
146
|
+
});
|
|
147
|
+
test('success if style matches with ignoreCase', async () => {
|
|
148
|
+
const el = await $('sel');
|
|
149
|
+
el._attempts = 0;
|
|
150
|
+
let counter = 0;
|
|
151
|
+
const actualStyle = {
|
|
152
|
+
'font-family': 'Faktum',
|
|
153
|
+
'font-size': '26px',
|
|
154
|
+
'color': '#fff'
|
|
155
|
+
};
|
|
156
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
157
|
+
counter++;
|
|
158
|
+
if (counter === Object.keys(mockStyle).length) {
|
|
159
|
+
counter = 0;
|
|
160
|
+
el._attempts++;
|
|
161
|
+
}
|
|
162
|
+
return { value: actualStyle[property] };
|
|
163
|
+
});
|
|
164
|
+
const alteredCaseStyle = {
|
|
165
|
+
'font-family': 'FaKtum',
|
|
166
|
+
'font-size': '26px',
|
|
167
|
+
'color': '#FFF'
|
|
168
|
+
};
|
|
169
|
+
const result = await toHaveStyle.call({}, el, alteredCaseStyle, { ignoreCase: true });
|
|
170
|
+
expect(result.pass).toBe(true);
|
|
171
|
+
expect(el._attempts).toBe(1);
|
|
172
|
+
});
|
|
173
|
+
test('success if style matches with trim', async () => {
|
|
174
|
+
const el = await $('sel');
|
|
175
|
+
el._attempts = 0;
|
|
176
|
+
let counter = 0;
|
|
177
|
+
const actualStyle = {
|
|
178
|
+
'font-family': ' Faktum ',
|
|
179
|
+
'font-size': ' 26px ',
|
|
180
|
+
'color': ' #fff '
|
|
181
|
+
};
|
|
182
|
+
el.getCSSProperty = vi.fn().mockImplementation((property) => {
|
|
183
|
+
counter++;
|
|
184
|
+
if (counter === Object.keys(mockStyle).length) {
|
|
185
|
+
counter = 0;
|
|
186
|
+
el._attempts++;
|
|
187
|
+
}
|
|
188
|
+
return { value: actualStyle[property] };
|
|
189
|
+
});
|
|
190
|
+
const alteredSpaceStyle = {
|
|
191
|
+
'font-family': 'Faktum',
|
|
192
|
+
'font-size': '26px',
|
|
193
|
+
'color': '#fff'
|
|
194
|
+
};
|
|
195
|
+
const result = await toHaveStyle.call({}, el, alteredSpaceStyle, { trim: true });
|
|
196
|
+
expect(result.pass).toBe(true);
|
|
197
|
+
expect(el._attempts).toBe(1);
|
|
198
|
+
});
|
|
199
|
+
});
|