expect-webdriverio 5.3.3 → 5.4.0

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.
Files changed (81) hide show
  1. package/jasmine.d.ts +1 -1
  2. package/lib/{src/matchers → matchers}/element/toHaveAttribute.js +1 -1
  3. package/lib/{tsconfig.tsbuildinfo → tsconfig.build.tsbuildinfo} +1 -1
  4. package/package.json +5 -3
  5. package/types/standalone.d.ts +2 -2
  6. package/lib/test/__fixtures__/utils.js +0 -19
  7. package/lib/test/index.test.js +0 -8
  8. package/lib/test/matchers/beMatchers.test.js +0 -109
  9. package/lib/test/matchers/browser/toHaveClipboardText.test.js +0 -21
  10. package/lib/test/matchers/browserMatchers.test.js +0 -102
  11. package/lib/test/matchers/element/toBeDisabled.test.js +0 -121
  12. package/lib/test/matchers/element/toHaveAttribute.test.js +0 -131
  13. package/lib/test/matchers/element/toHaveChildren.test.js +0 -62
  14. package/lib/test/matchers/element/toHaveComputedLabel.test.js +0 -284
  15. package/lib/test/matchers/element/toHaveComputedRole.test.js +0 -284
  16. package/lib/test/matchers/element/toHaveElementClass.test.js +0 -125
  17. package/lib/test/matchers/element/toHaveElementProperty.test.js +0 -111
  18. package/lib/test/matchers/element/toHaveHTML.test.js +0 -291
  19. package/lib/test/matchers/element/toHaveHeight.test.js +0 -171
  20. package/lib/test/matchers/element/toHaveHref.test.js +0 -54
  21. package/lib/test/matchers/element/toHaveId.test.js +0 -54
  22. package/lib/test/matchers/element/toHaveSize.test.js +0 -109
  23. package/lib/test/matchers/element/toHaveStyle.test.js +0 -199
  24. package/lib/test/matchers/element/toHaveText.test.js +0 -333
  25. package/lib/test/matchers/element/toHaveValue.test.js +0 -81
  26. package/lib/test/matchers/element/toHaveWidth.test.js +0 -171
  27. package/lib/test/matchers/elements/toBeElementsArrayOfSize.test.js +0 -141
  28. package/lib/test/matchers/mock/toBeRequested.test.js +0 -73
  29. package/lib/test/matchers/mock/toBeRequestedTimes.test.js +0 -108
  30. package/lib/test/matchers/mock/toBeRequestedWith.test.js +0 -343
  31. package/lib/test/matchers.test.js +0 -54
  32. package/lib/test/snapshot.test.js +0 -53
  33. package/lib/test/softAssertions.test.js +0 -332
  34. package/lib/test/util/elementsUtil.test.js +0 -18
  35. package/lib/test/util/formatMessage.test.js +0 -96
  36. package/lib/test/util/refetchElements.test.js +0 -19
  37. package/lib/test/utils.test.js +0 -117
  38. /package/lib/{src/constants.js → constants.js} +0 -0
  39. /package/lib/{src/index.js → index.js} +0 -0
  40. /package/lib/{src/jasmineUtils.js → jasmineUtils.js} +0 -0
  41. /package/lib/{src/matchers → matchers}/browser/toHaveClipboardText.js +0 -0
  42. /package/lib/{src/matchers → matchers}/browser/toHaveTitle.js +0 -0
  43. /package/lib/{src/matchers → matchers}/browser/toHaveUrl.js +0 -0
  44. /package/lib/{src/matchers → matchers}/element/toBeClickable.js +0 -0
  45. /package/lib/{src/matchers → matchers}/element/toBeDisabled.js +0 -0
  46. /package/lib/{src/matchers → matchers}/element/toBeDisplayed.js +0 -0
  47. /package/lib/{src/matchers → matchers}/element/toBeDisplayedInViewport.js +0 -0
  48. /package/lib/{src/matchers → matchers}/element/toBeEnabled.js +0 -0
  49. /package/lib/{src/matchers → matchers}/element/toBeExisting.js +0 -0
  50. /package/lib/{src/matchers → matchers}/element/toBeFocused.js +0 -0
  51. /package/lib/{src/matchers → matchers}/element/toBeSelected.js +0 -0
  52. /package/lib/{src/matchers → matchers}/element/toHaveChildren.js +0 -0
  53. /package/lib/{src/matchers → matchers}/element/toHaveClass.js +0 -0
  54. /package/lib/{src/matchers → matchers}/element/toHaveComputedLabel.js +0 -0
  55. /package/lib/{src/matchers → matchers}/element/toHaveComputedRole.js +0 -0
  56. /package/lib/{src/matchers → matchers}/element/toHaveElementProperty.js +0 -0
  57. /package/lib/{src/matchers → matchers}/element/toHaveHTML.js +0 -0
  58. /package/lib/{src/matchers → matchers}/element/toHaveHeight.js +0 -0
  59. /package/lib/{src/matchers → matchers}/element/toHaveHref.js +0 -0
  60. /package/lib/{src/matchers → matchers}/element/toHaveId.js +0 -0
  61. /package/lib/{src/matchers → matchers}/element/toHaveSize.js +0 -0
  62. /package/lib/{src/matchers → matchers}/element/toHaveStyle.js +0 -0
  63. /package/lib/{src/matchers → matchers}/element/toHaveText.js +0 -0
  64. /package/lib/{src/matchers → matchers}/element/toHaveValue.js +0 -0
  65. /package/lib/{src/matchers → matchers}/element/toHaveWidth.js +0 -0
  66. /package/lib/{src/matchers → matchers}/elements/toBeElementsArrayOfSize.js +0 -0
  67. /package/lib/{src/matchers → matchers}/mock/toBeRequested.js +0 -0
  68. /package/lib/{src/matchers → matchers}/mock/toBeRequestedTimes.js +0 -0
  69. /package/lib/{src/matchers → matchers}/mock/toBeRequestedWith.js +0 -0
  70. /package/lib/{src/matchers → matchers}/snapshot.js +0 -0
  71. /package/lib/{src/matchers.js → matchers.js} +0 -0
  72. /package/lib/{src/snapshot.js → snapshot.js} +0 -0
  73. /package/lib/{src/softAssert.js → softAssert.js} +0 -0
  74. /package/lib/{src/softAssertService.js → softAssertService.js} +0 -0
  75. /package/lib/{src/softExpect.js → softExpect.js} +0 -0
  76. /package/lib/{src/types.js → types.js} +0 -0
  77. /package/lib/{src/util → util}/elementsUtil.js +0 -0
  78. /package/lib/{src/util → util}/executeCommand.js +0 -0
  79. /package/lib/{src/util → util}/formatMessage.js +0 -0
  80. /package/lib/{src/util → util}/refetchElements.js +0 -0
  81. /package/lib/{src/utils.js → utils.js} +0 -0
@@ -1,284 +0,0 @@
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 { toHaveComputedLabel } from '../../../src/matchers/element/toHaveComputedLabel.js';
5
- vi.mock('@wdio/globals');
6
- describe('toHaveComputedLabel', () => {
7
- test('wait for success', async () => {
8
- const el = await $('sel');
9
- el._attempts = 2;
10
- el._computed_label = function () {
11
- if (this._attempts > 0) {
12
- this._attempts--;
13
- return '';
14
- }
15
- return 'WebdriverIO';
16
- };
17
- const beforeAssertion = vi.fn();
18
- const afterAssertion = vi.fn();
19
- const result = await toHaveComputedLabel.call({}, el, 'WebdriverIO', { ignoreCase: true, beforeAssertion, afterAssertion });
20
- expect(result.pass).toBe(true);
21
- expect(el._attempts).toBe(0);
22
- expect(beforeAssertion).toBeCalledWith({
23
- matcherName: 'toHaveComputedLabel',
24
- expectedValue: 'WebdriverIO',
25
- options: { ignoreCase: true, beforeAssertion, afterAssertion }
26
- });
27
- expect(afterAssertion).toBeCalledWith({
28
- matcherName: 'toHaveComputedLabel',
29
- expectedValue: 'WebdriverIO',
30
- options: { ignoreCase: true, beforeAssertion, afterAssertion },
31
- result
32
- });
33
- });
34
- test('wait but failure', async () => {
35
- const el = await $('sel');
36
- el._computed_label = function () {
37
- throw new Error('some error');
38
- };
39
- await expect(() => toHaveComputedLabel.call({}, el, 'WebdriverIO', { ignoreCase: true }))
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._computed_label = function () {
46
- this._attempts++;
47
- return 'WebdriverIO';
48
- };
49
- const result = await toHaveComputedLabel.call({}, el, 'WebdriverIO', { ignoreCase: true });
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._computed_label = function () {
57
- this._attempts++;
58
- return 'WebdriverIO';
59
- };
60
- const result = await toHaveComputedLabel.call({}, el, 'foo', { 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._computed_label = function () {
68
- this._attempts++;
69
- return 'WebdriverIO';
70
- };
71
- const result = await toHaveComputedLabel.call({}, el, 'WebdriverIO', { 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._computed_label = function () {
78
- return 'WebdriverIO';
79
- };
80
- const result = await toHaveComputedLabel.call({ isNot: true }, el, 'WebdriverIO', { 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 computed labels don't match", async () => {
86
- const el = await $('sel');
87
- el._computed_label = function () {
88
- return 'WebdriverIO';
89
- };
90
- const result = await toHaveComputedLabel.bind({ isNot: true })(el, 'foobar', { wait: 1 });
91
- expect(result.pass).toBe(false);
92
- });
93
- test('should return true if computed labels match', async () => {
94
- const el = await $('sel');
95
- el._computed_label = function () {
96
- return 'WebdriverIO';
97
- };
98
- const result = await toHaveComputedLabel.bind({ isNot: true })(el, 'WebdriverIO', { wait: 1 });
99
- expect(result.pass).toBe(true);
100
- });
101
- test('should return true if actual computed label + single replacer matches the expected computed label', async () => {
102
- const el = await $('sel');
103
- el._computed_label = function () {
104
- return 'WebdriverIO';
105
- };
106
- const result = await toHaveComputedLabel.bind({})(el, 'BrowserdriverIO', {
107
- replace: ['Web', 'Browser'],
108
- });
109
- expect(result.pass).toBe(true);
110
- });
111
- test('should return true if actual computed label + replace (string) matches the expected computed label', async () => {
112
- const el = await $('sel');
113
- el._computed_label = function () {
114
- return 'WebdriverIO';
115
- };
116
- const result = await toHaveComputedLabel.bind({})(el, 'BrowserdriverIO', {
117
- replace: [['Web', 'Browser']],
118
- });
119
- expect(result.pass).toBe(true);
120
- });
121
- test('should return true if actual computed label + replace (regex) matches the expected computed label', async () => {
122
- const el = await $('sel');
123
- el._computed_label = function () {
124
- return 'WebdriverIO';
125
- };
126
- const result = await toHaveComputedLabel.bind({})(el, 'BrowserdriverIO', {
127
- replace: [[/Web/, 'Browser']],
128
- });
129
- expect(result.pass).toBe(true);
130
- });
131
- test('should return true if actual computed label starts with expected computed label', async () => {
132
- const el = await $('sel');
133
- el._computed_label = function () {
134
- return 'WebdriverIO';
135
- };
136
- const result = await toHaveComputedLabel.bind({})(el, 'Webd', { atStart: true });
137
- expect(result.pass).toBe(true);
138
- });
139
- test('should return true if actual computed label ends with expected computed label', async () => {
140
- const el = await $('sel');
141
- el._computed_label = function () {
142
- return 'WebdriverIO';
143
- };
144
- const result = await toHaveComputedLabel.bind({})(el, 'erIO', { atEnd: true });
145
- expect(result.pass).toBe(true);
146
- });
147
- test('should return true if actual computed label contains the expected computed label at the given index', async () => {
148
- const el = await $('sel');
149
- el._computed_label = function () {
150
- return 'WebdriverIO';
151
- };
152
- const result = await toHaveComputedLabel.bind({})(el, 'iver', { atIndex: 5 });
153
- expect(result.pass).toBe(true);
154
- });
155
- test('message', async () => {
156
- const el = await $('sel');
157
- el._computed_label = function () {
158
- return '';
159
- };
160
- const result = await toHaveComputedLabel.call({}, el, 'WebdriverIO');
161
- expect(getExpectMessage(result.message())).toContain('to have computed label');
162
- });
163
- test('success if array matches with computed label and ignoreCase', async () => {
164
- const el = await $('sel');
165
- el._attempts = 0;
166
- el._computed_label = function () {
167
- this._attempts++;
168
- return 'WebdriverIO';
169
- };
170
- const result = await toHaveComputedLabel.call({}, el, ['div', 'WebdriverIO'], { ignoreCase: true });
171
- expect(result.pass).toBe(true);
172
- expect(el._attempts).toBe(1);
173
- });
174
- test('success if array matches with computed label and trim', async () => {
175
- const el = await $('sel');
176
- el._attempts = 0;
177
- el._computed_label = function () {
178
- this._attempts++;
179
- return ' WebdriverIO ';
180
- };
181
- const result = await toHaveComputedLabel.call({}, el, ['div', 'WebdriverIO', 'toto'], {
182
- trim: true,
183
- });
184
- expect(result.pass).toBe(true);
185
- expect(el._attempts).toBe(1);
186
- });
187
- test('success if array matches with computed label and replace (string)', async () => {
188
- const el = await $('sel');
189
- el._attempts = 0;
190
- el._computed_label = function () {
191
- this._attempts++;
192
- return 'WebdriverIO';
193
- };
194
- const result = await toHaveComputedLabel.call({}, el, ['div', 'BrowserdriverIO', 'toto'], {
195
- replace: [['Web', 'Browser']],
196
- });
197
- expect(result.pass).toBe(true);
198
- expect(el._attempts).toBe(1);
199
- });
200
- test('success if array matches with computed label and replace (regex)', async () => {
201
- const el = await $('sel');
202
- el._attempts = 0;
203
- el._computed_label = function () {
204
- this._attempts++;
205
- return 'WebdriverIO';
206
- };
207
- const result = await toHaveComputedLabel.call({}, el, ['div', 'BrowserdriverIO', 'toto'], {
208
- replace: [[/Web/g, 'Browser']],
209
- });
210
- expect(result.pass).toBe(true);
211
- expect(el._attempts).toBe(1);
212
- });
213
- test('success if array matches with computed label and multiple replacers and one of the replacers is a function', async () => {
214
- const el = await $('sel');
215
- el._attempts = 0;
216
- el._computed_label = function () {
217
- this._attempts++;
218
- return 'WebdriverIO';
219
- };
220
- const result = await toHaveComputedLabel.call({}, el, ['div', 'browserdriverio', 'toto'], {
221
- replace: [
222
- [/Web/g, 'Browser'],
223
- [/[A-Z]/g, (match) => match.toLowerCase()],
224
- ],
225
- });
226
- expect(result.pass).toBe(true);
227
- expect(el._attempts).toBe(1);
228
- });
229
- test('failure if array does not match with computed label', async () => {
230
- const el = await $('sel');
231
- el._attempts = 0;
232
- el._computed_label = function () {
233
- this._attempts++;
234
- return 'WebdriverIO';
235
- };
236
- const result = await toHaveComputedLabel.call({}, el, ['div', 'foo'], { wait: 1 });
237
- expect(result.pass).toBe(false);
238
- expect(el._attempts).toBe(1);
239
- });
240
- describe('with RegExp', () => {
241
- let el;
242
- beforeEach(async () => {
243
- el = await $('sel');
244
- el._computed_label = vi.fn().mockImplementation(() => {
245
- return 'This is example computed label';
246
- });
247
- });
248
- test('success if match', async () => {
249
- const result = await toHaveComputedLabel.call({}, el, /ExAmplE/i);
250
- expect(result.pass).toBe(true);
251
- });
252
- test('success if array matches with RegExp', async () => {
253
- const result = await toHaveComputedLabel.call({}, el, ['div', /ExAmPlE/i]);
254
- expect(result.pass).toBe(true);
255
- });
256
- test('success if array matches with computed label', async () => {
257
- const result = await toHaveComputedLabel.call({}, el, [
258
- 'This is example computed label',
259
- /Webdriver/i,
260
- ]);
261
- expect(result.pass).toBe(true);
262
- });
263
- test('success if array matches with computed label and ignoreCase', async () => {
264
- const result = await toHaveComputedLabel.call({}, el, ['ThIs Is ExAmPlE computed label', /Webdriver/i], {
265
- ignoreCase: true,
266
- });
267
- expect(result.pass).toBe(true);
268
- });
269
- test('failure if no match', async () => {
270
- const result = await toHaveComputedLabel.call({}, el, /Webdriver/i);
271
- expect(result.pass).toBe(false);
272
- expect(getExpectMessage(result.message())).toContain('to have computed label');
273
- expect(getExpected(result.message())).toContain('/Webdriver/i');
274
- expect(getReceived(result.message())).toContain('This is example computed label');
275
- });
276
- test('failure if array does not match with computed label', async () => {
277
- const result = await toHaveComputedLabel.call({}, el, ['div', /Webdriver/i]);
278
- expect(result.pass).toBe(false);
279
- expect(getExpectMessage(result.message())).toContain('to have computed label');
280
- expect(getExpected(result.message())).toContain('/Webdriver/i');
281
- expect(getExpected(result.message())).toContain('div');
282
- });
283
- });
284
- });
@@ -1,284 +0,0 @@
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 { toHaveComputedRole } from '../../../src/matchers/element/toHaveComputedRole.js';
5
- vi.mock('@wdio/globals');
6
- describe('toHaveComputedcomputed role', () => {
7
- test('wait for success', async () => {
8
- const el = await $('sel');
9
- el._attempts = 2;
10
- el._computed_role = function () {
11
- if (this._attempts > 0) {
12
- this._attempts--;
13
- return '';
14
- }
15
- return 'WebdriverIO';
16
- };
17
- const beforeAssertion = vi.fn();
18
- const afterAssertion = vi.fn();
19
- const result = await toHaveComputedRole.call({}, el, 'WebdriverIO', { ignoreCase: true, beforeAssertion, afterAssertion });
20
- expect(result.pass).toBe(true);
21
- expect(el._attempts).toBe(0);
22
- expect(beforeAssertion).toBeCalledWith({
23
- matcherName: 'toHaveComputedRole',
24
- expectedValue: 'WebdriverIO',
25
- options: { ignoreCase: true, beforeAssertion, afterAssertion }
26
- });
27
- expect(afterAssertion).toBeCalledWith({
28
- matcherName: 'toHaveComputedRole',
29
- expectedValue: 'WebdriverIO',
30
- options: { ignoreCase: true, beforeAssertion, afterAssertion },
31
- result
32
- });
33
- });
34
- test('wait but failure', async () => {
35
- const el = await $('sel');
36
- el._computed_role = function () {
37
- throw new Error('some error');
38
- };
39
- await expect(() => toHaveComputedRole.call({}, el, 'WebdriverIO', { ignoreCase: true }))
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._computed_role = function () {
46
- this._attempts++;
47
- return 'WebdriverIO';
48
- };
49
- const result = await toHaveComputedRole.call({}, el, 'WebdriverIO', { ignoreCase: true });
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._computed_role = function () {
57
- this._attempts++;
58
- return 'WebdriverIO';
59
- };
60
- const result = await toHaveComputedRole.call({}, el, 'foo', { 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._computed_role = function () {
68
- this._attempts++;
69
- return 'WebdriverIO';
70
- };
71
- const result = await toHaveComputedRole.call({}, el, 'WebdriverIO', { 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._computed_role = function () {
78
- return 'WebdriverIO';
79
- };
80
- const result = await toHaveComputedRole.call({ isNot: true }, el, 'WebdriverIO', { 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 computed roles don't match", async () => {
86
- const el = await $('sel');
87
- el._computed_role = function () {
88
- return 'WebdriverIO';
89
- };
90
- const result = await toHaveComputedRole.bind({ isNot: true })(el, 'foobar', { wait: 1 });
91
- expect(result.pass).toBe(false);
92
- });
93
- test('should return true if computed roles match', async () => {
94
- const el = await $('sel');
95
- el._computed_role = function () {
96
- return 'WebdriverIO';
97
- };
98
- const result = await toHaveComputedRole.bind({ isNot: true })(el, 'WebdriverIO', { wait: 1 });
99
- expect(result.pass).toBe(true);
100
- });
101
- test('should return true if actual computed role + single replacer matches the expected computed role', async () => {
102
- const el = await $('sel');
103
- el._computed_role = function () {
104
- return 'WebdriverIO';
105
- };
106
- const result = await toHaveComputedRole.bind({})(el, 'BrowserdriverIO', {
107
- replace: ['Web', 'Browser'],
108
- });
109
- expect(result.pass).toBe(true);
110
- });
111
- test('should return true if actual computed role + replace (string) matches the expected computed role', async () => {
112
- const el = await $('sel');
113
- el._computed_role = function () {
114
- return 'WebdriverIO';
115
- };
116
- const result = await toHaveComputedRole.bind({})(el, 'BrowserdriverIO', {
117
- replace: [['Web', 'Browser']],
118
- });
119
- expect(result.pass).toBe(true);
120
- });
121
- test('should return true if actual computed role + replace (regex) matches the expected computed role', async () => {
122
- const el = await $('sel');
123
- el._computed_role = function () {
124
- return 'WebdriverIO';
125
- };
126
- const result = await toHaveComputedRole.bind({})(el, 'BrowserdriverIO', {
127
- replace: [[/Web/, 'Browser']],
128
- });
129
- expect(result.pass).toBe(true);
130
- });
131
- test('should return true if actual computed role starts with expected computed role', async () => {
132
- const el = await $('sel');
133
- el._computed_role = function () {
134
- return 'WebdriverIO';
135
- };
136
- const result = await toHaveComputedRole.bind({})(el, 'Webd', { atStart: true });
137
- expect(result.pass).toBe(true);
138
- });
139
- test('should return true if actual computed role ends with expected computed role', async () => {
140
- const el = await $('sel');
141
- el._computed_role = function () {
142
- return 'WebdriverIO';
143
- };
144
- const result = await toHaveComputedRole.bind({})(el, 'erIO', { atEnd: true });
145
- expect(result.pass).toBe(true);
146
- });
147
- test('should return true if actual computed role contains the expected computed role at the given index', async () => {
148
- const el = await $('sel');
149
- el._computed_role = function () {
150
- return 'WebdriverIO';
151
- };
152
- const result = await toHaveComputedRole.bind({})(el, 'iver', { atIndex: 5 });
153
- expect(result.pass).toBe(true);
154
- });
155
- test('message', async () => {
156
- const el = await $('sel');
157
- el._computed_role = function () {
158
- return '';
159
- };
160
- const result = await toHaveComputedRole.call({}, el, 'WebdriverIO');
161
- expect(getExpectMessage(result.message())).toContain('to have computed role');
162
- });
163
- test('success if array matches with computed role and ignoreCase', async () => {
164
- const el = await $('sel');
165
- el._attempts = 0;
166
- el._computed_role = function () {
167
- this._attempts++;
168
- return 'WebdriverIO';
169
- };
170
- const result = await toHaveComputedRole.call({}, el, ['div', 'WebdriverIO'], { ignoreCase: true });
171
- expect(result.pass).toBe(true);
172
- expect(el._attempts).toBe(1);
173
- });
174
- test('success if array matches with computed role and trim', async () => {
175
- const el = await $('sel');
176
- el._attempts = 0;
177
- el._computed_role = function () {
178
- this._attempts++;
179
- return ' WebdriverIO ';
180
- };
181
- const result = await toHaveComputedRole.call({}, el, ['div', 'WebdriverIO', 'toto'], {
182
- trim: true,
183
- });
184
- expect(result.pass).toBe(true);
185
- expect(el._attempts).toBe(1);
186
- });
187
- test('success if array matches with computed role and replace (string)', async () => {
188
- const el = await $('sel');
189
- el._attempts = 0;
190
- el._computed_role = function () {
191
- this._attempts++;
192
- return 'WebdriverIO';
193
- };
194
- const result = await toHaveComputedRole.call({}, el, ['div', 'BrowserdriverIO', 'toto'], {
195
- replace: [['Web', 'Browser']],
196
- });
197
- expect(result.pass).toBe(true);
198
- expect(el._attempts).toBe(1);
199
- });
200
- test('success if array matches with computed role and replace (regex)', async () => {
201
- const el = await $('sel');
202
- el._attempts = 0;
203
- el._computed_role = function () {
204
- this._attempts++;
205
- return 'WebdriverIO';
206
- };
207
- const result = await toHaveComputedRole.call({}, el, ['div', 'BrowserdriverIO', 'toto'], {
208
- replace: [[/Web/g, 'Browser']],
209
- });
210
- expect(result.pass).toBe(true);
211
- expect(el._attempts).toBe(1);
212
- });
213
- test('success if array matches with computed role and multiple replacers and one of the replacers is a function', async () => {
214
- const el = await $('sel');
215
- el._attempts = 0;
216
- el._computed_role = function () {
217
- this._attempts++;
218
- return 'WebdriverIO';
219
- };
220
- const result = await toHaveComputedRole.call({}, el, ['div', 'browserdriverio', 'toto'], {
221
- replace: [
222
- [/Web/g, 'Browser'],
223
- [/[A-Z]/g, (match) => match.toLowerCase()],
224
- ],
225
- });
226
- expect(result.pass).toBe(true);
227
- expect(el._attempts).toBe(1);
228
- });
229
- test('failure if array does not match with computed role', async () => {
230
- const el = await $('sel');
231
- el._attempts = 0;
232
- el._computed_role = function () {
233
- this._attempts++;
234
- return 'WebdriverIO';
235
- };
236
- const result = await toHaveComputedRole.call({}, el, ['div', 'foo'], { wait: 1 });
237
- expect(result.pass).toBe(false);
238
- expect(el._attempts).toBe(1);
239
- });
240
- describe('with RegExp', () => {
241
- let el;
242
- beforeEach(async () => {
243
- el = await $('sel');
244
- el._computed_role = vi.fn().mockImplementation(() => {
245
- return 'This is example computed role';
246
- });
247
- });
248
- test('success if match', async () => {
249
- const result = await toHaveComputedRole.call({}, el, /ExAmplE/i);
250
- expect(result.pass).toBe(true);
251
- });
252
- test('success if array matches with RegExp', async () => {
253
- const result = await toHaveComputedRole.call({}, el, ['div', /ExAmPlE/i]);
254
- expect(result.pass).toBe(true);
255
- });
256
- test('success if array matches with computed role', async () => {
257
- const result = await toHaveComputedRole.call({}, el, [
258
- 'This is example computed role',
259
- /Webdriver/i,
260
- ]);
261
- expect(result.pass).toBe(true);
262
- });
263
- test('success if array matches with computed role and ignoreCase', async () => {
264
- const result = await toHaveComputedRole.call({}, el, ['ThIs Is ExAmPlE computed role', /Webdriver/i], {
265
- ignoreCase: true,
266
- });
267
- expect(result.pass).toBe(true);
268
- });
269
- test('failure if no match', async () => {
270
- const result = await toHaveComputedRole.call({}, el, /Webdriver/i);
271
- expect(result.pass).toBe(false);
272
- expect(getExpectMessage(result.message())).toContain('to have computed role');
273
- expect(getExpected(result.message())).toContain('/Webdriver/i');
274
- expect(getReceived(result.message())).toContain('This is example computed role');
275
- });
276
- test('failure if array does not match with computed role', async () => {
277
- const result = await toHaveComputedRole.call({}, el, ['div', /Webdriver/i]);
278
- expect(result.pass).toBe(false);
279
- expect(getExpectMessage(result.message())).toContain('to have computed role');
280
- expect(getExpected(result.message())).toContain('/Webdriver/i');
281
- expect(getExpected(result.message())).toContain('div');
282
- });
283
- });
284
- });