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,343 +0,0 @@
|
|
|
1
|
-
import { vi, test, describe, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { toBeRequestedWith } from '../../../src/matchers/mock/toBeRequestedWith.js';
|
|
3
|
-
import { removeColors, getExpectMessage, getExpected, getReceived } from '../../__fixtures__/utils.js';
|
|
4
|
-
vi.mock('@wdio/globals');
|
|
5
|
-
class TestMock {
|
|
6
|
-
constructor() {
|
|
7
|
-
this._calls = [];
|
|
8
|
-
}
|
|
9
|
-
get calls() {
|
|
10
|
-
return this._calls;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function reduceHeaders(headers) {
|
|
14
|
-
return Object.entries(headers).reduce((acc, [, value]) => {
|
|
15
|
-
acc[value.name] = value.value.value;
|
|
16
|
-
return acc;
|
|
17
|
-
}, {});
|
|
18
|
-
}
|
|
19
|
-
const authKey = 'Bearer ' + '2'.repeat(128);
|
|
20
|
-
const mockGet = {
|
|
21
|
-
request: {
|
|
22
|
-
url: 'http://localhost:8080/api/search?pages=20',
|
|
23
|
-
method: 'GET',
|
|
24
|
-
request: '123',
|
|
25
|
-
headersSize: 123,
|
|
26
|
-
bodySize: 123,
|
|
27
|
-
timings: {},
|
|
28
|
-
cookies: [],
|
|
29
|
-
headers: [{
|
|
30
|
-
name: 'Authorization',
|
|
31
|
-
value: { type: 'string', value: authKey }
|
|
32
|
-
}, {
|
|
33
|
-
name: 'foo',
|
|
34
|
-
value: { type: 'string', value: 'bar' }
|
|
35
|
-
}]
|
|
36
|
-
},
|
|
37
|
-
response: {
|
|
38
|
-
headers: {},
|
|
39
|
-
status: 200,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
const mockPost = {
|
|
43
|
-
request: {
|
|
44
|
-
url: 'https://my-app/api/add-tags',
|
|
45
|
-
method: 'POST',
|
|
46
|
-
request: '123',
|
|
47
|
-
headersSize: 123,
|
|
48
|
-
bodySize: 123,
|
|
49
|
-
timings: {},
|
|
50
|
-
cookies: [],
|
|
51
|
-
headers: [{
|
|
52
|
-
name: 'Authorization',
|
|
53
|
-
value: { type: 'string', value: authKey }
|
|
54
|
-
}, {
|
|
55
|
-
name: 'foo',
|
|
56
|
-
value: { type: 'string', value: 'bar' }
|
|
57
|
-
}, {
|
|
58
|
-
name: 'Accept',
|
|
59
|
-
value: { type: 'string', value: '*' }
|
|
60
|
-
}],
|
|
61
|
-
},
|
|
62
|
-
response: {
|
|
63
|
-
status: 201,
|
|
64
|
-
headers: []
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
describe('toBeRequestedWith', () => {
|
|
68
|
-
test('wait for success, exact match', async () => {
|
|
69
|
-
const mock = new TestMock();
|
|
70
|
-
setTimeout(() => {
|
|
71
|
-
mock.calls.push({ ...mockGet });
|
|
72
|
-
}, 5);
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
mock.calls.push({ ...mockGet }, { ...mockPost });
|
|
75
|
-
}, 15);
|
|
76
|
-
const params = {
|
|
77
|
-
url: mockPost.request.url,
|
|
78
|
-
method: mockPost.request.method,
|
|
79
|
-
requestHeaders: {},
|
|
80
|
-
statusCode: mockPost.response.status,
|
|
81
|
-
responseHeaders: {},
|
|
82
|
-
};
|
|
83
|
-
const beforeAssertion = vi.fn();
|
|
84
|
-
const afterAssertion = vi.fn();
|
|
85
|
-
const result = await toBeRequestedWith.call({}, mock, params, { beforeAssertion, afterAssertion });
|
|
86
|
-
expect(result.pass).toBe(true);
|
|
87
|
-
expect(beforeAssertion).toBeCalledWith({
|
|
88
|
-
matcherName: 'toBeRequestedWith',
|
|
89
|
-
expectedValue: params,
|
|
90
|
-
options: { beforeAssertion, afterAssertion },
|
|
91
|
-
});
|
|
92
|
-
expect(afterAssertion).toBeCalledWith({
|
|
93
|
-
matcherName: 'toBeRequestedWith',
|
|
94
|
-
expectedValue: params,
|
|
95
|
-
options: { beforeAssertion, afterAssertion },
|
|
96
|
-
result
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
test('wait for failure', async () => {
|
|
100
|
-
const mock = new TestMock();
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
mock.calls.push({ ...mockGet }, { ...mockPost });
|
|
103
|
-
}, 15);
|
|
104
|
-
const params = {
|
|
105
|
-
url: 'post.url',
|
|
106
|
-
method: 'post.method',
|
|
107
|
-
requestHeaders: {},
|
|
108
|
-
responseHeaders: {}
|
|
109
|
-
};
|
|
110
|
-
const result = await toBeRequestedWith.call({}, mock, params);
|
|
111
|
-
expect(result.pass).toBe(false);
|
|
112
|
-
});
|
|
113
|
-
test('wait for NOT failure, empty params', async () => {
|
|
114
|
-
const mock = new TestMock();
|
|
115
|
-
mock.calls.push({ ...mockGet }, { ...mockPost });
|
|
116
|
-
setTimeout(() => {
|
|
117
|
-
mock.calls.push({ ...mockGet }, { ...mockPost });
|
|
118
|
-
}, 10);
|
|
119
|
-
const result = await toBeRequestedWith.call({ isNot: true }, mock, {});
|
|
120
|
-
expect(result.pass).toBe(true);
|
|
121
|
-
});
|
|
122
|
-
test('wait for NOT success', async () => {
|
|
123
|
-
const mock = new TestMock();
|
|
124
|
-
setTimeout(() => {
|
|
125
|
-
mock.calls.push({ ...mockGet }, { ...mockPost });
|
|
126
|
-
}, 10);
|
|
127
|
-
const result = await toBeRequestedWith.call({ isNot: true }, mock, { method: 'DELETE' });
|
|
128
|
-
expect(result.pass).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
const scenarios = [
|
|
131
|
-
{
|
|
132
|
-
name: 'success, url only',
|
|
133
|
-
mocks: [{ ...mockPost }],
|
|
134
|
-
pass: true,
|
|
135
|
-
params: {
|
|
136
|
-
url: mockPost.request.url,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: 'success, method only',
|
|
141
|
-
mocks: [{ ...mockPost }],
|
|
142
|
-
pass: true,
|
|
143
|
-
params: {
|
|
144
|
-
method: ['DELETE', 'PUT', mockPost.request.method, 'GET'],
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
name: 'success, statusCode only',
|
|
149
|
-
mocks: [{ ...mockPost }],
|
|
150
|
-
pass: true,
|
|
151
|
-
params: {
|
|
152
|
-
statusCode: [203, 200, 201],
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
name: 'success, requestHeaders only',
|
|
157
|
-
mocks: [{ ...mockPost }],
|
|
158
|
-
pass: true,
|
|
159
|
-
params: {
|
|
160
|
-
requestHeaders: {
|
|
161
|
-
Authorization: authKey,
|
|
162
|
-
foo: 'bar',
|
|
163
|
-
Accept: '*'
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: 'success, responseHeaders only',
|
|
169
|
-
mocks: [{ ...mockPost }],
|
|
170
|
-
pass: true,
|
|
171
|
-
params: {
|
|
172
|
-
responseHeaders: {},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
name: 'failure, url only',
|
|
177
|
-
mocks: [{ ...mockPost }],
|
|
178
|
-
pass: false,
|
|
179
|
-
params: {
|
|
180
|
-
url: '/api/api',
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
name: 'failure, method only',
|
|
185
|
-
mocks: [{ ...mockPost }],
|
|
186
|
-
pass: false,
|
|
187
|
-
params: {
|
|
188
|
-
method: ['DELETE', 'PUT'],
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name: 'failure, statusCode only',
|
|
193
|
-
mocks: [{ ...mockPost }],
|
|
194
|
-
pass: false,
|
|
195
|
-
params: {
|
|
196
|
-
statusCode: [400, 401],
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
name: 'failure, requestHeaders only',
|
|
201
|
-
mocks: [{ ...mockPost }],
|
|
202
|
-
pass: false,
|
|
203
|
-
params: {
|
|
204
|
-
requestHeaders: { Cache: 'false' },
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
name: 'failure, responseHeaders only',
|
|
209
|
-
mocks: [{ ...mockPost }],
|
|
210
|
-
pass: false,
|
|
211
|
-
params: {
|
|
212
|
-
responseHeaders: { Cache: 'false' },
|
|
213
|
-
},
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
name: 'special matcher, url',
|
|
217
|
-
mocks: [{ ...mockPost }],
|
|
218
|
-
pass: true,
|
|
219
|
-
params: {
|
|
220
|
-
url: expect.stringMatching(/.*\/API\/.*/i),
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
name: 'special matcher, headers',
|
|
225
|
-
mocks: [{ ...mockPost }],
|
|
226
|
-
pass: true,
|
|
227
|
-
params: {
|
|
228
|
-
requestHeaders: expect.objectContaining({
|
|
229
|
-
Authorization: expect.stringContaining('Bearer '),
|
|
230
|
-
}),
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
name: 'special matcher, postData',
|
|
235
|
-
mocks: [{ ...mockPost }],
|
|
236
|
-
pass: true,
|
|
237
|
-
params: {
|
|
238
|
-
postData: expect.stringMatching('"search"'),
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
name: 'special matcher, response',
|
|
243
|
-
mocks: [{ ...mockPost }],
|
|
244
|
-
pass: true,
|
|
245
|
-
params: {
|
|
246
|
-
response: expect.arrayContaining([expect.objectContaining({ id: 2 })]),
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
name: 'function, url',
|
|
251
|
-
mocks: [{ ...mockPost }],
|
|
252
|
-
pass: true,
|
|
253
|
-
params: {
|
|
254
|
-
url: (url) => url.startsWith('https'),
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
name: 'function, headers',
|
|
259
|
-
mocks: [{ ...mockPost }],
|
|
260
|
-
pass: true,
|
|
261
|
-
params: {
|
|
262
|
-
requestHeaders: (headers) => headers.foo === 'bar',
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
name: 'function, postData',
|
|
267
|
-
mocks: [{ ...mockPost }],
|
|
268
|
-
pass: true,
|
|
269
|
-
params: {
|
|
270
|
-
postData: (r) => JSON.parse(r).length === 2,
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
name: 'function, response',
|
|
275
|
-
mocks: [{ ...mockPost }],
|
|
276
|
-
pass: true,
|
|
277
|
-
params: {
|
|
278
|
-
response: (r) => r.includes('id') && r.includes('name'),
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
];
|
|
282
|
-
scenarios.forEach((scenario) => {
|
|
283
|
-
test(scenario.name, async () => {
|
|
284
|
-
const mock = new TestMock();
|
|
285
|
-
mock.calls.push(...scenario.mocks);
|
|
286
|
-
const result = await toBeRequestedWith.call({}, mock, scenario.params);
|
|
287
|
-
expect(result.pass).toBe(scenario.pass);
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
describe('error messages', () => {
|
|
291
|
-
const consoleError = global.console.error;
|
|
292
|
-
beforeEach(() => {
|
|
293
|
-
global.console.error = vi.fn();
|
|
294
|
-
});
|
|
295
|
-
test('unsupported method', async () => {
|
|
296
|
-
const mock = new TestMock();
|
|
297
|
-
mock.calls.push({ ...mockGet });
|
|
298
|
-
const result = await toBeRequestedWith.call({}, mock, { method: 1234 });
|
|
299
|
-
expect(result.pass).toBe(false);
|
|
300
|
-
expect(global.console.error).toBeCalledWith('expect.toBeRequestedWith: unsupported value passed to method 1234');
|
|
301
|
-
});
|
|
302
|
-
afterEach(() => {
|
|
303
|
-
global.console.error = consoleError;
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
test('message', async () => {
|
|
307
|
-
const mock = new TestMock();
|
|
308
|
-
const requested = await toBeRequestedWith.call({}, mock, {
|
|
309
|
-
url: () => false,
|
|
310
|
-
method: ['DELETE', 'PUT'],
|
|
311
|
-
requestHeaders: reduceHeaders(mockPost.request.headers),
|
|
312
|
-
responseHeaders: reduceHeaders(mockPost.response.headers),
|
|
313
|
-
postData: expect.anything(),
|
|
314
|
-
response: [...Array(50).keys()].map((_, id) => ({ id, name: `name_${id}` })),
|
|
315
|
-
});
|
|
316
|
-
const wasNotCalled = removeColors(requested.message());
|
|
317
|
-
expect(getExpectMessage(wasNotCalled)).toBe('Expect mock to be called with');
|
|
318
|
-
expect(getExpected(wasNotCalled)).toBe('Expected: {' +
|
|
319
|
-
'"method": ["DELETE", "PUT"], ' +
|
|
320
|
-
'"postData": "Anything ", ' +
|
|
321
|
-
'"requestHeaders": {"Accept": "*", "Authorization": "Bearer ..2222222", "foo": "bar"}, ' +
|
|
322
|
-
'"response": [{"id": 0, "name": "name_0"}, "... 49 more items"], ' +
|
|
323
|
-
'"responseHeaders": {}, ' +
|
|
324
|
-
'"url": "() => false"}');
|
|
325
|
-
expect(getReceived(wasNotCalled)).toBe('Received: "was not called"');
|
|
326
|
-
mock.calls.push(mockPost);
|
|
327
|
-
const notRequested = await toBeRequestedWith.call({ isNot: true }, mock, {
|
|
328
|
-
url: () => true,
|
|
329
|
-
method: mockPost.request.method,
|
|
330
|
-
});
|
|
331
|
-
const wasCalled = removeColors(notRequested.message());
|
|
332
|
-
expect(wasCalled).toBe(`Expect mock not to be called with
|
|
333
|
-
|
|
334
|
-
- Expected [not] - 1
|
|
335
|
-
+ Received + 1
|
|
336
|
-
|
|
337
|
-
Object {
|
|
338
|
-
"method": "POST",
|
|
339
|
-
- "url": "() => true",
|
|
340
|
-
+ "url": "https://my-app/api/add-tags",
|
|
341
|
-
}`);
|
|
342
|
-
});
|
|
343
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { test, expect, vi } from 'vitest';
|
|
2
|
-
import { matchers, expect as expectLib } from '../src/index.js';
|
|
3
|
-
const ALL_MATCHERS = [
|
|
4
|
-
'toHaveClipboardText',
|
|
5
|
-
'toHaveTitle',
|
|
6
|
-
'toHaveUrl',
|
|
7
|
-
'toBeClickable',
|
|
8
|
-
'toBeDisabled',
|
|
9
|
-
'toBeDisplayed',
|
|
10
|
-
'toBeDisplayedInViewport',
|
|
11
|
-
'toBeEnabled',
|
|
12
|
-
'toExist',
|
|
13
|
-
'toBeExisting',
|
|
14
|
-
'toBePresent',
|
|
15
|
-
'toBeFocused',
|
|
16
|
-
'toBeSelected',
|
|
17
|
-
'toBeChecked',
|
|
18
|
-
'toHaveAttributeAndValue',
|
|
19
|
-
'toHaveAttribute',
|
|
20
|
-
'toHaveAttr',
|
|
21
|
-
'toHaveChildren',
|
|
22
|
-
'toHaveClass',
|
|
23
|
-
'toHaveElementClass',
|
|
24
|
-
'toHaveClassContaining',
|
|
25
|
-
'toHaveComputedLabel',
|
|
26
|
-
'toHaveComputedRole',
|
|
27
|
-
'toHaveElementProperty',
|
|
28
|
-
'toHaveHeight',
|
|
29
|
-
'toHaveHref',
|
|
30
|
-
'toHaveLink',
|
|
31
|
-
'toHaveHTML',
|
|
32
|
-
'toHaveId',
|
|
33
|
-
'toHaveSize',
|
|
34
|
-
'toHaveStyle',
|
|
35
|
-
'toHaveText',
|
|
36
|
-
'toHaveValue',
|
|
37
|
-
'toHaveWidth',
|
|
38
|
-
'toBeElementsArrayOfSize',
|
|
39
|
-
'toBeRequested',
|
|
40
|
-
'toBeRequestedTimes',
|
|
41
|
-
'toBeRequestedWith',
|
|
42
|
-
'toBeRequestedWithResponse',
|
|
43
|
-
'toMatchSnapshot',
|
|
44
|
-
'toMatchInlineSnapshot'
|
|
45
|
-
];
|
|
46
|
-
test('matchers', () => {
|
|
47
|
-
expect([...matchers.keys()]).toEqual(ALL_MATCHERS);
|
|
48
|
-
});
|
|
49
|
-
test('allows to add matcher', () => {
|
|
50
|
-
const matcher = vi.fn((actual, expected) => ({ pass: actual === expected }));
|
|
51
|
-
expectLib.extend({ toBeCustom: matcher });
|
|
52
|
-
expectLib('foo').toBeCustom('foo');
|
|
53
|
-
expect(matchers.keys()).toContain('toBeCustom');
|
|
54
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { test, expect } from 'vitest';
|
|
5
|
-
import { expect as expectExport, SnapshotService } from '../src/index.js';
|
|
6
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const __filename = path.basename(fileURLToPath(import.meta.url));
|
|
8
|
-
const service = SnapshotService.initiate({
|
|
9
|
-
resolveSnapshotPath: (path, extension) => path + extension
|
|
10
|
-
});
|
|
11
|
-
test('supports snapshot testing', async () => {
|
|
12
|
-
await service.beforeTest({
|
|
13
|
-
title: 'test',
|
|
14
|
-
parent: 'parent',
|
|
15
|
-
file: path.join(__dirname, __filename),
|
|
16
|
-
});
|
|
17
|
-
process.env.WDIO_INTERNAL_TEST = 'true';
|
|
18
|
-
const exp = expectExport;
|
|
19
|
-
expect(exp).toBeDefined();
|
|
20
|
-
expect(exp({}).toMatchSnapshot).toBeDefined();
|
|
21
|
-
expect(exp({}).toMatchInlineSnapshot).toBeDefined();
|
|
22
|
-
await exp({ a: 'a' }).toMatchSnapshot();
|
|
23
|
-
await exp({ deep: { nested: { object: 'value' } } }).toMatchInlineSnapshot(`
|
|
24
|
-
{
|
|
25
|
-
"deep": {
|
|
26
|
-
"nested": {
|
|
27
|
-
"object": "value",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
`);
|
|
32
|
-
await service.after();
|
|
33
|
-
const expectedSnapfileExist = await fs.access(path.resolve(__dirname, 'snapshot.test.ts.snap'))
|
|
34
|
-
.then(() => true, () => false);
|
|
35
|
-
expect(expectedSnapfileExist).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
test('supports cucumber snapshot testing', async () => {
|
|
38
|
-
await service.beforeStep({
|
|
39
|
-
text: 'Fake step',
|
|
40
|
-
}, {
|
|
41
|
-
name: 'Fake scenario',
|
|
42
|
-
uri: `${__dirname}/file.feature`,
|
|
43
|
-
});
|
|
44
|
-
const exp = expectExport;
|
|
45
|
-
expect(exp).toBeDefined();
|
|
46
|
-
expect(exp({}).toMatchSnapshot).toBeDefined();
|
|
47
|
-
expect(exp({}).toMatchInlineSnapshot).toBeDefined();
|
|
48
|
-
await exp({ cucum: 'ber' }).toMatchSnapshot();
|
|
49
|
-
await service.after();
|
|
50
|
-
const expectedSnapfileExist = await fs.access(path.resolve(__dirname, 'file.feature.snap'))
|
|
51
|
-
.then(() => true, () => false);
|
|
52
|
-
expect(expectedSnapfileExist).toBe(true);
|
|
53
|
-
});
|