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,333 @@
|
|
|
1
|
+
import { $, $$ } from '@wdio/globals';
|
|
2
|
+
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
+
import { getExpectMessage, getReceived, getExpected } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveText } from '../../../src/matchers/element/toHaveText.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveText', () => {
|
|
7
|
+
describe('when receiving an element array', () => {
|
|
8
|
+
let els;
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
els = await $$('parent');
|
|
11
|
+
const el1 = await $('sel');
|
|
12
|
+
el1._text = function () {
|
|
13
|
+
return 'WebdriverIO';
|
|
14
|
+
};
|
|
15
|
+
const el2 = await $('dev');
|
|
16
|
+
el2._text = function () {
|
|
17
|
+
return 'Get Started';
|
|
18
|
+
};
|
|
19
|
+
els[0] = el1;
|
|
20
|
+
els[1] = el2;
|
|
21
|
+
});
|
|
22
|
+
test('should return true if the received element array matches the expected text array', async () => {
|
|
23
|
+
const result = await toHaveText.bind({})(els, ['WebdriverIO', 'Get Started']);
|
|
24
|
+
expect(result.pass).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
test('should return true if the received element array matches the expected text array & ignoreCase', async () => {
|
|
27
|
+
const result = await toHaveText.bind({})(els, ['webdriverio', 'get started'], { ignoreCase: true });
|
|
28
|
+
expect(result.pass).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
test('should return false if the received element array does not match the expected text array', async () => {
|
|
31
|
+
const result = await toHaveText.bind({})(els, ['webdriverio', 'get started']);
|
|
32
|
+
expect(result.pass).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
test('should return true if the expected message shows correctly', async () => {
|
|
35
|
+
const result = await toHaveText.bind({})(els, ['webdriverio', 'get started'], { message: 'Test' });
|
|
36
|
+
expect(getExpectMessage(result.message())).toContain('Test');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
test('wait for success', async () => {
|
|
40
|
+
const el = await $('sel');
|
|
41
|
+
el._attempts = 2;
|
|
42
|
+
el._text = function () {
|
|
43
|
+
if (this._attempts > 0) {
|
|
44
|
+
this._attempts--;
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
return 'webdriverio';
|
|
48
|
+
};
|
|
49
|
+
const beforeAssertion = vi.fn();
|
|
50
|
+
const afterAssertion = vi.fn();
|
|
51
|
+
const result = await toHaveText.call({}, el, 'WebdriverIO', { ignoreCase: true, beforeAssertion, afterAssertion });
|
|
52
|
+
expect(result.pass).toBe(true);
|
|
53
|
+
expect(el._attempts).toBe(0);
|
|
54
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
55
|
+
matcherName: 'toHaveText',
|
|
56
|
+
expectedValue: 'WebdriverIO',
|
|
57
|
+
options: { ignoreCase: true, beforeAssertion, afterAssertion }
|
|
58
|
+
});
|
|
59
|
+
expect(afterAssertion).toBeCalledWith({
|
|
60
|
+
matcherName: 'toHaveText',
|
|
61
|
+
expectedValue: 'WebdriverIO',
|
|
62
|
+
options: { ignoreCase: true, beforeAssertion, afterAssertion },
|
|
63
|
+
result
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
test('wait but failure', async () => {
|
|
67
|
+
const el = await $('sel');
|
|
68
|
+
el._text = function () {
|
|
69
|
+
throw new Error('some error');
|
|
70
|
+
};
|
|
71
|
+
await expect(() => toHaveText.call({}, el, 'WebdriverIO', { ignoreCase: true }))
|
|
72
|
+
.rejects.toThrow('some error');
|
|
73
|
+
});
|
|
74
|
+
test('success on the first attempt', async () => {
|
|
75
|
+
const el = await $('sel');
|
|
76
|
+
el._attempts = 0;
|
|
77
|
+
el._text = function () {
|
|
78
|
+
this._attempts++;
|
|
79
|
+
return 'WebdriverIO';
|
|
80
|
+
};
|
|
81
|
+
const result = await toHaveText.call({}, el, 'WebdriverIO', { ignoreCase: true });
|
|
82
|
+
expect(result.pass).toBe(true);
|
|
83
|
+
expect(el._attempts).toBe(1);
|
|
84
|
+
});
|
|
85
|
+
test('no wait - failure', async () => {
|
|
86
|
+
const el = await $('sel');
|
|
87
|
+
el._attempts = 0;
|
|
88
|
+
el._text = function () {
|
|
89
|
+
this._attempts++;
|
|
90
|
+
return 'webdriverio';
|
|
91
|
+
};
|
|
92
|
+
const result = await toHaveText.call({}, el, 'WebdriverIO', { wait: 0 });
|
|
93
|
+
expect(result.pass).toBe(false);
|
|
94
|
+
expect(el._attempts).toBe(1);
|
|
95
|
+
});
|
|
96
|
+
test('no wait - success', async () => {
|
|
97
|
+
const el = await $('sel');
|
|
98
|
+
el._attempts = 0;
|
|
99
|
+
el._text = function () {
|
|
100
|
+
this._attempts++;
|
|
101
|
+
return 'WebdriverIO';
|
|
102
|
+
};
|
|
103
|
+
const result = await toHaveText.call({}, el, 'WebdriverIO', { wait: 0 });
|
|
104
|
+
expect(result.pass).toBe(true);
|
|
105
|
+
expect(el._attempts).toBe(1);
|
|
106
|
+
});
|
|
107
|
+
test('not - failure', async () => {
|
|
108
|
+
const el = await $('sel');
|
|
109
|
+
el._text = function () {
|
|
110
|
+
return 'WebdriverIO';
|
|
111
|
+
};
|
|
112
|
+
const result = await toHaveText.call({ isNot: true }, el, 'WebdriverIO', { wait: 0 });
|
|
113
|
+
const received = getReceived(result.message());
|
|
114
|
+
expect(received).not.toContain('not');
|
|
115
|
+
expect(result.pass).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
test('should return false if texts don\'t match', async () => {
|
|
118
|
+
const el = await $('sel');
|
|
119
|
+
el._text = function () {
|
|
120
|
+
return 'WebdriverIO';
|
|
121
|
+
};
|
|
122
|
+
const result = await toHaveText.bind({ isNot: true })(el, 'foobar', { wait: 1 });
|
|
123
|
+
expect(result.pass).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
test('should return true if texts match', async () => {
|
|
126
|
+
const el = await $('sel');
|
|
127
|
+
el._text = function () {
|
|
128
|
+
return 'WebdriverIO';
|
|
129
|
+
};
|
|
130
|
+
const result = await toHaveText.bind({ isNot: true })(el, 'WebdriverIO', { wait: 1 });
|
|
131
|
+
expect(result.pass).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
test('should return true if actual text + single replacer matches the expected text', async () => {
|
|
134
|
+
const el = await $('sel');
|
|
135
|
+
el._text = function () {
|
|
136
|
+
return 'WebdriverIO';
|
|
137
|
+
};
|
|
138
|
+
const result = await toHaveText.bind({})(el, 'BrowserdriverIO', { replace: ['Web', 'Browser'] });
|
|
139
|
+
expect(result.pass).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
test('should return true if actual text + replace (string) matches the expected text', async () => {
|
|
142
|
+
const el = await $('sel');
|
|
143
|
+
el._text = function () {
|
|
144
|
+
return 'WebdriverIO';
|
|
145
|
+
};
|
|
146
|
+
const result = await toHaveText.bind({})(el, 'BrowserdriverIO', { replace: [['Web', 'Browser']] });
|
|
147
|
+
expect(result.pass).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
test('should return true if actual text + replace (regex) matches the expected text', async () => {
|
|
150
|
+
const el = await $('sel');
|
|
151
|
+
el._text = function () {
|
|
152
|
+
return 'WebdriverIO';
|
|
153
|
+
};
|
|
154
|
+
const result = await toHaveText.bind({})(el, 'BrowserdriverIO', { replace: [[/Web/, 'Browser']] });
|
|
155
|
+
expect(result.pass).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
test('should return true if actual text starts with expected text', async () => {
|
|
158
|
+
const el = await $('sel');
|
|
159
|
+
el._text = function () {
|
|
160
|
+
return 'WebdriverIO';
|
|
161
|
+
};
|
|
162
|
+
const result = await toHaveText.bind({})(el, 'Web', { atStart: true });
|
|
163
|
+
expect(result.pass).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
test('should return true if actual text ends with expected text', async () => {
|
|
166
|
+
const el = await $('sel');
|
|
167
|
+
el._text = function () {
|
|
168
|
+
return 'WebdriverIO';
|
|
169
|
+
};
|
|
170
|
+
const result = await toHaveText.bind({})(el, 'IO', { atEnd: true });
|
|
171
|
+
expect(result.pass).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
test('should return true if actual text contains the expected text at the given index', async () => {
|
|
174
|
+
const el = await $('sel');
|
|
175
|
+
el._text = function () {
|
|
176
|
+
return 'WebdriverIO';
|
|
177
|
+
};
|
|
178
|
+
const result = await toHaveText.bind({})(el, 'iverIO', { atIndex: 5 });
|
|
179
|
+
expect(result.pass).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
test('message', async () => {
|
|
182
|
+
const el = await $('sel');
|
|
183
|
+
el._text = function () {
|
|
184
|
+
return '';
|
|
185
|
+
};
|
|
186
|
+
const result = await toHaveText.call({}, el, 'WebdriverIO');
|
|
187
|
+
expect(getExpectMessage(result.message())).toContain('to have text');
|
|
188
|
+
});
|
|
189
|
+
test('success if array matches with text and ignoreCase', async () => {
|
|
190
|
+
const el = await $('sel');
|
|
191
|
+
el._attempts = 0;
|
|
192
|
+
el._text = function () {
|
|
193
|
+
this._attempts++;
|
|
194
|
+
return 'WebdriverIO';
|
|
195
|
+
};
|
|
196
|
+
const result = await toHaveText.call({}, el, ['WDIO', 'Webdriverio'], { ignoreCase: true });
|
|
197
|
+
expect(result.pass).toBe(true);
|
|
198
|
+
expect(el._attempts).toBe(1);
|
|
199
|
+
});
|
|
200
|
+
test('success if array matches with text and trim', async () => {
|
|
201
|
+
const el = await $('sel');
|
|
202
|
+
el._attempts = 0;
|
|
203
|
+
el._text = function () {
|
|
204
|
+
this._attempts++;
|
|
205
|
+
return ' WebdriverIO ';
|
|
206
|
+
};
|
|
207
|
+
const result = await toHaveText.call({}, el, ['WDIO', 'WebdriverIO', 'toto'], { trim: true });
|
|
208
|
+
expect(result.pass).toBe(true);
|
|
209
|
+
expect(el._attempts).toBe(1);
|
|
210
|
+
});
|
|
211
|
+
test('success if array matches with text and replace (string)', async () => {
|
|
212
|
+
const el = await $('sel');
|
|
213
|
+
el._attempts = 0;
|
|
214
|
+
el._text = function () {
|
|
215
|
+
this._attempts++;
|
|
216
|
+
return 'WebdriverIO';
|
|
217
|
+
};
|
|
218
|
+
const result = await toHaveText.call({}, el, ['WDIO', 'BrowserdriverIO', 'toto'], { replace: [['Web', 'Browser']] });
|
|
219
|
+
expect(result.pass).toBe(true);
|
|
220
|
+
expect(el._attempts).toBe(1);
|
|
221
|
+
});
|
|
222
|
+
test('success if array matches with text and replace (regex)', async () => {
|
|
223
|
+
const el = await $('sel');
|
|
224
|
+
el._attempts = 0;
|
|
225
|
+
el._text = function () {
|
|
226
|
+
this._attempts++;
|
|
227
|
+
return 'WebdriverIO';
|
|
228
|
+
};
|
|
229
|
+
const result = await toHaveText.call({}, el, ['WDIO', 'BrowserdriverIO', 'toto'], { replace: [[/Web/g, 'Browser']] });
|
|
230
|
+
expect(result.pass).toBe(true);
|
|
231
|
+
expect(el._attempts).toBe(1);
|
|
232
|
+
});
|
|
233
|
+
test('success if array matches with text and multiple replacers and one of the replacers is a function', async () => {
|
|
234
|
+
const el = await $('sel');
|
|
235
|
+
el._attempts = 0;
|
|
236
|
+
el._text = function () {
|
|
237
|
+
this._attempts++;
|
|
238
|
+
return 'WebdriverIO';
|
|
239
|
+
};
|
|
240
|
+
const result = await toHaveText.call({}, el, ['WDIO', 'browserdriverio', 'toto'], {
|
|
241
|
+
replace: [
|
|
242
|
+
[/Web/g, 'Browser'],
|
|
243
|
+
[/[A-Z]/g, (match) => match.toLowerCase()],
|
|
244
|
+
],
|
|
245
|
+
});
|
|
246
|
+
expect(result.pass).toBe(true);
|
|
247
|
+
expect(el._attempts).toBe(1);
|
|
248
|
+
});
|
|
249
|
+
test('failure if array does not match with text', async () => {
|
|
250
|
+
const el = await $('sel');
|
|
251
|
+
el._attempts = 0;
|
|
252
|
+
el._text = function () {
|
|
253
|
+
this._attempts++;
|
|
254
|
+
return 'WebdriverIO';
|
|
255
|
+
};
|
|
256
|
+
const result = await toHaveText.call({}, el, ['WDIO', 'Webdriverio'], { wait: 1 });
|
|
257
|
+
expect(result.pass).toBe(false);
|
|
258
|
+
expect(el._attempts).toBe(1);
|
|
259
|
+
});
|
|
260
|
+
test('should return true if actual text contains the expected text', async () => {
|
|
261
|
+
const el = await $('sel');
|
|
262
|
+
el._text = function () {
|
|
263
|
+
return 'WebdriverIO';
|
|
264
|
+
};
|
|
265
|
+
const result = await toHaveText.bind({})(el, expect.stringContaining('iverIO'), {});
|
|
266
|
+
expect(result.pass).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
test('should return false if actual text does not contain the expected text', async () => {
|
|
269
|
+
const el = await $('sel');
|
|
270
|
+
el._text = function () {
|
|
271
|
+
return 'WebdriverIO';
|
|
272
|
+
};
|
|
273
|
+
const result = await toHaveText.bind({})(el, expect.stringContaining('WDIO'), {});
|
|
274
|
+
expect(result.pass).toBe(false);
|
|
275
|
+
});
|
|
276
|
+
test('should return true if actual text contains one of the expected texts', async () => {
|
|
277
|
+
const el = await $('sel');
|
|
278
|
+
el._text = function () {
|
|
279
|
+
return 'WebdriverIO';
|
|
280
|
+
};
|
|
281
|
+
const result = await toHaveText.bind({})(el, [expect.stringContaining('iverIO'), expect.stringContaining('WDIO')], {});
|
|
282
|
+
expect(result.pass).toBe(true);
|
|
283
|
+
});
|
|
284
|
+
test('should return false if actual text does not contain the expected texts', async () => {
|
|
285
|
+
const el = await $('sel');
|
|
286
|
+
el._text = function () {
|
|
287
|
+
return 'WebdriverIO';
|
|
288
|
+
};
|
|
289
|
+
const result = await toHaveText.bind({})(el, [expect.stringContaining('EXAMPLE'), expect.stringContaining('WDIO')], {});
|
|
290
|
+
expect(result.pass).toBe(false);
|
|
291
|
+
});
|
|
292
|
+
describe('with RegExp', () => {
|
|
293
|
+
let el;
|
|
294
|
+
beforeEach(async () => {
|
|
295
|
+
el = await $('sel');
|
|
296
|
+
el._text = vi.fn().mockImplementation(() => {
|
|
297
|
+
return 'This is example text';
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
test('success if match', async () => {
|
|
301
|
+
const result = await toHaveText.call({}, el, /ExAmplE/i);
|
|
302
|
+
expect(result.pass).toBe(true);
|
|
303
|
+
});
|
|
304
|
+
test('success if array matches with RegExp', async () => {
|
|
305
|
+
const result = await toHaveText.call({}, el, ['WDIO', /ExAmPlE/i]);
|
|
306
|
+
expect(result.pass).toBe(true);
|
|
307
|
+
});
|
|
308
|
+
test('success if array matches with text', async () => {
|
|
309
|
+
const result = await toHaveText.call({}, el, ['This is example text', /Webdriver/i]);
|
|
310
|
+
expect(result.pass).toBe(true);
|
|
311
|
+
});
|
|
312
|
+
test('success if array matches with text and ignoreCase', async () => {
|
|
313
|
+
const result = await toHaveText.call({}, el, ['ThIs Is ExAmPlE tExT', /Webdriver/i], {
|
|
314
|
+
ignoreCase: true,
|
|
315
|
+
});
|
|
316
|
+
expect(result.pass).toBe(true);
|
|
317
|
+
});
|
|
318
|
+
test('failure if no match', async () => {
|
|
319
|
+
const result = await toHaveText.call({}, el, /Webdriver/i);
|
|
320
|
+
expect(result.pass).toBe(false);
|
|
321
|
+
expect(getExpectMessage(result.message())).toContain('to have text');
|
|
322
|
+
expect(getExpected(result.message())).toContain('/Webdriver/i');
|
|
323
|
+
expect(getReceived(result.message())).toContain('This is example text');
|
|
324
|
+
});
|
|
325
|
+
test('failure if array does not match with text', async () => {
|
|
326
|
+
const result = await toHaveText.call({}, el, ['WDIO', /Webdriver/i]);
|
|
327
|
+
expect(result.pass).toBe(false);
|
|
328
|
+
expect(getExpectMessage(result.message())).toContain('to have text');
|
|
329
|
+
expect(getExpected(result.message())).toContain('/Webdriver/i');
|
|
330
|
+
expect(getExpected(result.message())).toContain('WDIO');
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { vi, test, describe, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { $ } from '@wdio/globals';
|
|
3
|
+
import { getExpectMessage, getReceived, getExpected } from '../../__fixtures__/utils.js';
|
|
4
|
+
import { toHaveValue } from '../../../src/matchers/element/toHaveValue.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveValue', () => {
|
|
7
|
+
let el;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
el = await $('sel');
|
|
10
|
+
el._value = vi.fn().mockImplementation(() => {
|
|
11
|
+
return 'This is an example value';
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe('success', () => {
|
|
15
|
+
test('exact passes', async () => {
|
|
16
|
+
const beforeAssertion = vi.fn();
|
|
17
|
+
const afterAssertion = vi.fn();
|
|
18
|
+
const result = await toHaveValue.call({}, el, 'This is an example value', { beforeAssertion, afterAssertion });
|
|
19
|
+
expect(result.pass).toBe(true);
|
|
20
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
21
|
+
matcherName: 'toHaveElementProperty',
|
|
22
|
+
expectedValue: ['value', 'This is an example value'],
|
|
23
|
+
options: { beforeAssertion, afterAssertion }
|
|
24
|
+
});
|
|
25
|
+
expect(afterAssertion).toBeCalledWith({
|
|
26
|
+
matcherName: 'toHaveElementProperty',
|
|
27
|
+
expectedValue: ['value', 'This is an example value'],
|
|
28
|
+
options: { beforeAssertion, afterAssertion },
|
|
29
|
+
result
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
test('assymetric passes', async () => {
|
|
33
|
+
const result = await toHaveValue.call({}, el, expect.stringContaining('example value'));
|
|
34
|
+
expect(result.pass).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
test('RegExp passes', async () => {
|
|
37
|
+
const result = await toHaveValue.call({}, el, /ExAmPlE/i);
|
|
38
|
+
expect(result.pass).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('failure', () => {
|
|
42
|
+
let result;
|
|
43
|
+
beforeEach(async () => {
|
|
44
|
+
result = await toHaveValue.call({}, el, 'webdriver');
|
|
45
|
+
});
|
|
46
|
+
test('does not pass', () => {
|
|
47
|
+
expect(result.pass).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
describe('message shows correctly', () => {
|
|
50
|
+
test('expect message', () => {
|
|
51
|
+
expect(getExpectMessage(result.message())).toContain('to have property value');
|
|
52
|
+
});
|
|
53
|
+
test('expected message', () => {
|
|
54
|
+
expect(getExpected(result.message())).toContain('webdriver');
|
|
55
|
+
});
|
|
56
|
+
test('received message', () => {
|
|
57
|
+
expect(getReceived(result.message())).toContain('This is an example value');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('failure with RegExp', () => {
|
|
62
|
+
let result;
|
|
63
|
+
beforeEach(async () => {
|
|
64
|
+
result = await toHaveValue.call({}, el, /WDIO/);
|
|
65
|
+
});
|
|
66
|
+
test('does not pass', () => {
|
|
67
|
+
expect(result.pass).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
describe('message shows correctly', () => {
|
|
70
|
+
test('expect message', () => {
|
|
71
|
+
expect(getExpectMessage(result.message())).toContain('to have property value');
|
|
72
|
+
});
|
|
73
|
+
test('expected message', () => {
|
|
74
|
+
expect(getExpected(result.message())).toContain('/WDIO/');
|
|
75
|
+
});
|
|
76
|
+
test('received message', () => {
|
|
77
|
+
expect(getReceived(result.message())).toContain('This is an example value');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -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 { toHaveWidth } from '../../../src/matchers/element/toHaveWidth.js';
|
|
5
|
+
vi.mock('@wdio/globals');
|
|
6
|
+
describe('toHaveWidth', () => {
|
|
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 toHaveWidth.call({}, el, 50, { beforeAssertion, afterAssertion });
|
|
26
|
+
expect(result.pass).toBe(true);
|
|
27
|
+
expect(el._attempts).toBe(0);
|
|
28
|
+
expect(beforeAssertion).toBeCalledWith({
|
|
29
|
+
matcherName: 'toHaveWidth',
|
|
30
|
+
expectedValue: 50,
|
|
31
|
+
options: { beforeAssertion, afterAssertion }
|
|
32
|
+
});
|
|
33
|
+
expect(afterAssertion).toBeCalledWith({
|
|
34
|
+
matcherName: 'toHaveWidth',
|
|
35
|
+
expectedValue: 50,
|
|
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(() => toHaveWidth.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 toHaveWidth.call({}, el, 50, {});
|
|
62
|
+
expect(result.message()).toEqual('Expect $(`sel`) to have width\n\nExpected: 50\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 toHaveWidth.call({}, el, 10, { wait: 0 });
|
|
80
|
+
expect(result.message()).toEqual('Expect $(`sel`) to have width\n\nExpected: 10\nReceived: 50');
|
|
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 toHaveWidth.call({}, el, 50, { 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 toHaveWidth.call({}, el, { gte: 49, lte: 51 }, { wait: 0 });
|
|
115
|
+
expect(result.message()).toEqual('Expect $(`sel`) to have width\n\nExpected: ">= 49 && <= 51"\nReceived: 50');
|
|
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 toHaveWidth.call({}, el, 50, { 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 toHaveWidth.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 toHaveWidth.bind({})(el, 50, { 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 toHaveWidth.call({}, el, 50);
|
|
169
|
+
expect(getExpectMessage(result.message())).toContain('to have width');
|
|
170
|
+
});
|
|
171
|
+
});
|