expect-webdriverio 5.3.3 → 5.3.4
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/{tsconfig.tsbuildinfo → tsconfig.build.tsbuildinfo} +1 -1
- package/package.json +2 -2
- package/types/expect-webdriverio.d.ts +27 -38
- package/types/standalone.d.ts +0 -2
- package/lib/test/__fixtures__/utils.js +0 -19
- package/lib/test/index.test.js +0 -8
- package/lib/test/matchers/beMatchers.test.js +0 -109
- package/lib/test/matchers/browser/toHaveClipboardText.test.js +0 -21
- package/lib/test/matchers/browserMatchers.test.js +0 -102
- package/lib/test/matchers/element/toBeDisabled.test.js +0 -121
- package/lib/test/matchers/element/toHaveAttribute.test.js +0 -131
- package/lib/test/matchers/element/toHaveChildren.test.js +0 -62
- package/lib/test/matchers/element/toHaveComputedLabel.test.js +0 -284
- package/lib/test/matchers/element/toHaveComputedRole.test.js +0 -284
- package/lib/test/matchers/element/toHaveElementClass.test.js +0 -125
- package/lib/test/matchers/element/toHaveElementProperty.test.js +0 -111
- package/lib/test/matchers/element/toHaveHTML.test.js +0 -291
- package/lib/test/matchers/element/toHaveHeight.test.js +0 -171
- package/lib/test/matchers/element/toHaveHref.test.js +0 -54
- package/lib/test/matchers/element/toHaveId.test.js +0 -54
- package/lib/test/matchers/element/toHaveSize.test.js +0 -109
- package/lib/test/matchers/element/toHaveStyle.test.js +0 -199
- package/lib/test/matchers/element/toHaveText.test.js +0 -333
- package/lib/test/matchers/element/toHaveValue.test.js +0 -81
- package/lib/test/matchers/element/toHaveWidth.test.js +0 -171
- package/lib/test/matchers/elements/toBeElementsArrayOfSize.test.js +0 -141
- package/lib/test/matchers/mock/toBeRequested.test.js +0 -73
- package/lib/test/matchers/mock/toBeRequestedTimes.test.js +0 -108
- package/lib/test/matchers/mock/toBeRequestedWith.test.js +0 -343
- package/lib/test/matchers.test.js +0 -54
- package/lib/test/snapshot.test.js +0 -53
- package/lib/test/softAssertions.test.js +0 -332
- package/lib/test/util/elementsUtil.test.js +0 -18
- package/lib/test/util/formatMessage.test.js +0 -96
- package/lib/test/util/refetchElements.test.js +0 -19
- package/lib/test/utils.test.js +0 -117
- /package/lib/{src/constants.js → constants.js} +0 -0
- /package/lib/{src/index.js → index.js} +0 -0
- /package/lib/{src/jasmineUtils.js → jasmineUtils.js} +0 -0
- /package/lib/{src/matchers → matchers}/browser/toHaveClipboardText.js +0 -0
- /package/lib/{src/matchers → matchers}/browser/toHaveTitle.js +0 -0
- /package/lib/{src/matchers → matchers}/browser/toHaveUrl.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeClickable.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeDisabled.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeDisplayed.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeDisplayedInViewport.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeEnabled.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeExisting.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeFocused.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toBeSelected.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveAttribute.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveChildren.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveClass.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveComputedLabel.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveComputedRole.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveElementProperty.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveHTML.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveHeight.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveHref.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveId.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveSize.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveStyle.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveText.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveValue.js +0 -0
- /package/lib/{src/matchers → matchers}/element/toHaveWidth.js +0 -0
- /package/lib/{src/matchers → matchers}/elements/toBeElementsArrayOfSize.js +0 -0
- /package/lib/{src/matchers → matchers}/mock/toBeRequested.js +0 -0
- /package/lib/{src/matchers → matchers}/mock/toBeRequestedTimes.js +0 -0
- /package/lib/{src/matchers → matchers}/mock/toBeRequestedWith.js +0 -0
- /package/lib/{src/matchers → matchers}/snapshot.js +0 -0
- /package/lib/{src/matchers.js → matchers.js} +0 -0
- /package/lib/{src/snapshot.js → snapshot.js} +0 -0
- /package/lib/{src/softAssert.js → softAssert.js} +0 -0
- /package/lib/{src/softAssertService.js → softAssertService.js} +0 -0
- /package/lib/{src/softExpect.js → softExpect.js} +0 -0
- /package/lib/{src/types.js → types.js} +0 -0
- /package/lib/{src/util → util}/elementsUtil.js +0 -0
- /package/lib/{src/util → util}/executeCommand.js +0 -0
- /package/lib/{src/util → util}/formatMessage.js +0 -0
- /package/lib/{src/util → util}/refetchElements.js +0 -0
- /package/lib/{src/utils.js → utils.js} +0 -0
|
@@ -1,199 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,333 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,81 +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 { 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
|
-
});
|