ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / matchers / matchers.js
Blame History Raw 384 lines
1
"use strict";
2
var __defProp = Object.defineProperty;
3
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
var __getOwnPropNames = Object.getOwnPropertyNames;
5
var __hasOwnProp = Object.prototype.hasOwnProperty;
6
var __export = (target, all) => {
7
for (var name in all)
8
__defProp(target, name, { get: all[name], enumerable: true });
9
};
10
var __copyProps = (to, from, except, desc) => {
11
if (from && typeof from === "object" || typeof from === "function") {
12
for (let key of __getOwnPropNames(from))
13
if (!__hasOwnProp.call(to, key) && key !== except)
14
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
}
16
return to;
17
};
18
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
var matchers_exports = {};
20
__export(matchers_exports, {
21
computeMatcherTitleSuffix: () => computeMatcherTitleSuffix,
22
toBeAttached: () => toBeAttached,
23
toBeChecked: () => toBeChecked,
24
toBeDisabled: () => toBeDisabled,
25
toBeEditable: () => toBeEditable,
26
toBeEmpty: () => toBeEmpty,
27
toBeEnabled: () => toBeEnabled,
28
toBeFocused: () => toBeFocused,
29
toBeHidden: () => toBeHidden,
30
toBeInViewport: () => toBeInViewport,
31
toBeOK: () => toBeOK,
32
toBeVisible: () => toBeVisible,
33
toContainClass: () => toContainClass,
34
toContainText: () => toContainText,
35
toHaveAccessibleDescription: () => toHaveAccessibleDescription,
36
toHaveAccessibleErrorMessage: () => toHaveAccessibleErrorMessage,
37
toHaveAccessibleName: () => toHaveAccessibleName,
38
toHaveAttribute: () => toHaveAttribute,
39
toHaveCSS: () => toHaveCSS,
40
toHaveClass: () => toHaveClass,
41
toHaveCount: () => toHaveCount,
42
toHaveId: () => toHaveId,
43
toHaveJSProperty: () => toHaveJSProperty,
44
toHaveRole: () => toHaveRole,
45
toHaveText: () => toHaveText,
46
toHaveTitle: () => toHaveTitle,
47
toHaveURL: () => toHaveURL,
48
toHaveValue: () => toHaveValue,
49
toHaveValues: () => toHaveValues,
50
toPass: () => toPass
51
});
52
module.exports = __toCommonJS(matchers_exports);
53
var import_utils = require("playwright-core/lib/utils");
54
var import_utils2 = require("playwright-core/lib/utils");
55
var import_util = require("../util");
56
var import_toBeTruthy = require("./toBeTruthy");
57
var import_toEqual = require("./toEqual");
58
var import_toHaveURL = require("./toHaveURL");
59
var import_toMatchText = require("./toMatchText");
60
var import_toMatchSnapshot = require("./toMatchSnapshot");
61
var import_config = require("../common/config");
62
var import_globals = require("../common/globals");
63
var import_testInfo = require("../worker/testInfo");
64
function toBeAttached(locator, options) {
65
const attached = !options || options.attached === void 0 || options.attached;
66
const expected = attached ? "attached" : "detached";
67
const arg = attached ? "" : "{ attached: false }";
68
return import_toBeTruthy.toBeTruthy.call(this, "toBeAttached", locator, "Locator", expected, arg, async (isNot, timeout) => {
69
return await locator._expect(attached ? "to.be.attached" : "to.be.detached", { isNot, timeout });
70
}, options);
71
}
72
function toBeChecked(locator, options) {
73
const checked = options?.checked;
74
const indeterminate = options?.indeterminate;
75
const expectedValue = {
76
checked,
77
indeterminate
78
};
79
let expected;
80
let arg;
81
if (options?.indeterminate) {
82
expected = "indeterminate";
83
arg = `{ indeterminate: true }`;
84
} else {
85
expected = options?.checked === false ? "unchecked" : "checked";
86
arg = options?.checked === false ? `{ checked: false }` : "";
87
}
88
return import_toBeTruthy.toBeTruthy.call(this, "toBeChecked", locator, "Locator", expected, arg, async (isNot, timeout) => {
89
return await locator._expect("to.be.checked", { isNot, timeout, expectedValue });
90
}, options);
91
}
92
function toBeDisabled(locator, options) {
93
return import_toBeTruthy.toBeTruthy.call(this, "toBeDisabled", locator, "Locator", "disabled", "", async (isNot, timeout) => {
94
return await locator._expect("to.be.disabled", { isNot, timeout });
95
}, options);
96
}
97
function toBeEditable(locator, options) {
98
const editable = !options || options.editable === void 0 || options.editable;
99
const expected = editable ? "editable" : "readOnly";
100
const arg = editable ? "" : "{ editable: false }";
101
return import_toBeTruthy.toBeTruthy.call(this, "toBeEditable", locator, "Locator", expected, arg, async (isNot, timeout) => {
102
return await locator._expect(editable ? "to.be.editable" : "to.be.readonly", { isNot, timeout });
103
}, options);
104
}
105
function toBeEmpty(locator, options) {
106
return import_toBeTruthy.toBeTruthy.call(this, "toBeEmpty", locator, "Locator", "empty", "", async (isNot, timeout) => {
107
return await locator._expect("to.be.empty", { isNot, timeout });
108
}, options);
109
}
110
function toBeEnabled(locator, options) {
111
const enabled = !options || options.enabled === void 0 || options.enabled;
112
const expected = enabled ? "enabled" : "disabled";
113
const arg = enabled ? "" : "{ enabled: false }";
114
return import_toBeTruthy.toBeTruthy.call(this, "toBeEnabled", locator, "Locator", expected, arg, async (isNot, timeout) => {
115
return await locator._expect(enabled ? "to.be.enabled" : "to.be.disabled", { isNot, timeout });
116
}, options);
117
}
118
function toBeFocused(locator, options) {
119
return import_toBeTruthy.toBeTruthy.call(this, "toBeFocused", locator, "Locator", "focused", "", async (isNot, timeout) => {
120
return await locator._expect("to.be.focused", { isNot, timeout });
121
}, options);
122
}
123
function toBeHidden(locator, options) {
124
return import_toBeTruthy.toBeTruthy.call(this, "toBeHidden", locator, "Locator", "hidden", "", async (isNot, timeout) => {
125
return await locator._expect("to.be.hidden", { isNot, timeout });
126
}, options);
127
}
128
function toBeVisible(locator, options) {
129
const visible = !options || options.visible === void 0 || options.visible;
130
const expected = visible ? "visible" : "hidden";
131
const arg = visible ? "" : "{ visible: false }";
132
return import_toBeTruthy.toBeTruthy.call(this, "toBeVisible", locator, "Locator", expected, arg, async (isNot, timeout) => {
133
return await locator._expect(visible ? "to.be.visible" : "to.be.hidden", { isNot, timeout });
134
}, options);
135
}
136
function toBeInViewport(locator, options) {
137
return import_toBeTruthy.toBeTruthy.call(this, "toBeInViewport", locator, "Locator", "in viewport", "", async (isNot, timeout) => {
138
return await locator._expect("to.be.in.viewport", { isNot, expectedNumber: options?.ratio, timeout });
139
}, options);
140
}
141
function toContainText(locator, expected, options = {}) {
142
if (Array.isArray(expected)) {
143
return import_toEqual.toEqual.call(this, "toContainText", locator, "Locator", async (isNot, timeout) => {
144
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected, { matchSubstring: true, normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
145
return await locator._expect("to.contain.text.array", { expectedText, isNot, useInnerText: options.useInnerText, timeout });
146
}, expected, { ...options, contains: true });
147
} else {
148
return import_toMatchText.toMatchText.call(this, "toContainText", locator, "Locator", async (isNot, timeout) => {
149
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { matchSubstring: true, normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
150
return await locator._expect("to.have.text", { expectedText, isNot, useInnerText: options.useInnerText, timeout });
151
}, expected, { ...options, matchSubstring: true });
152
}
153
}
154
function toHaveAccessibleDescription(locator, expected, options) {
155
return import_toMatchText.toMatchText.call(this, "toHaveAccessibleDescription", locator, "Locator", async (isNot, timeout) => {
156
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true });
157
return await locator._expect("to.have.accessible.description", { expectedText, isNot, timeout });
158
}, expected, options);
159
}
160
function toHaveAccessibleName(locator, expected, options) {
161
return import_toMatchText.toMatchText.call(this, "toHaveAccessibleName", locator, "Locator", async (isNot, timeout) => {
162
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true });
163
return await locator._expect("to.have.accessible.name", { expectedText, isNot, timeout });
164
}, expected, options);
165
}
166
function toHaveAccessibleErrorMessage(locator, expected, options) {
167
return import_toMatchText.toMatchText.call(this, "toHaveAccessibleErrorMessage", locator, "Locator", async (isNot, timeout) => {
168
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase, normalizeWhiteSpace: true });
169
return await locator._expect("to.have.accessible.error.message", { expectedText, isNot, timeout });
170
}, expected, options);
171
}
172
function toHaveAttribute(locator, name, expected, options) {
173
if (!options) {
174
if (typeof expected === "object" && !(0, import_utils.isRegExp)(expected)) {
175
options = expected;
176
expected = void 0;
177
}
178
}
179
if (expected === void 0) {
180
return import_toBeTruthy.toBeTruthy.call(this, "toHaveAttribute", locator, "Locator", "have attribute", "", async (isNot, timeout) => {
181
return await locator._expect("to.have.attribute", { expressionArg: name, isNot, timeout });
182
}, options);
183
}
184
return import_toMatchText.toMatchText.call(this, "toHaveAttribute", locator, "Locator", async (isNot, timeout) => {
185
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase });
186
return await locator._expect("to.have.attribute.value", { expressionArg: name, expectedText, isNot, timeout });
187
}, expected, options);
188
}
189
function toHaveClass(locator, expected, options) {
190
if (Array.isArray(expected)) {
191
return import_toEqual.toEqual.call(this, "toHaveClass", locator, "Locator", async (isNot, timeout) => {
192
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected);
193
return await locator._expect("to.have.class.array", { expectedText, isNot, timeout });
194
}, expected, options);
195
} else {
196
return import_toMatchText.toMatchText.call(this, "toHaveClass", locator, "Locator", async (isNot, timeout) => {
197
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
198
return await locator._expect("to.have.class", { expectedText, isNot, timeout });
199
}, expected, options);
200
}
201
}
202
function toContainClass(locator, expected, options) {
203
if (Array.isArray(expected)) {
204
if (expected.some((e) => (0, import_utils.isRegExp)(e)))
205
throw new Error(`"expected" argument in toContainClass cannot contain RegExp values`);
206
return import_toEqual.toEqual.call(this, "toContainClass", locator, "Locator", async (isNot, timeout) => {
207
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected);
208
return await locator._expect("to.contain.class.array", { expectedText, isNot, timeout });
209
}, expected, options);
210
} else {
211
if ((0, import_utils.isRegExp)(expected))
212
throw new Error(`"expected" argument in toContainClass cannot be a RegExp value`);
213
return import_toMatchText.toMatchText.call(this, "toContainClass", locator, "Locator", async (isNot, timeout) => {
214
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
215
return await locator._expect("to.contain.class", { expectedText, isNot, timeout });
216
}, expected, options);
217
}
218
}
219
function toHaveCount(locator, expected, options) {
220
return import_toEqual.toEqual.call(this, "toHaveCount", locator, "Locator", async (isNot, timeout) => {
221
return await locator._expect("to.have.count", { expectedNumber: expected, isNot, timeout });
222
}, expected, options);
223
}
224
function toHaveCSS(locator, name, expected, options) {
225
return import_toMatchText.toMatchText.call(this, "toHaveCSS", locator, "Locator", async (isNot, timeout) => {
226
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
227
return await locator._expect("to.have.css", { expressionArg: name, expectedText, isNot, timeout });
228
}, expected, options);
229
}
230
function toHaveId(locator, expected, options) {
231
return import_toMatchText.toMatchText.call(this, "toHaveId", locator, "Locator", async (isNot, timeout) => {
232
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
233
return await locator._expect("to.have.id", { expectedText, isNot, timeout });
234
}, expected, options);
235
}
236
function toHaveJSProperty(locator, name, expected, options) {
237
return import_toEqual.toEqual.call(this, "toHaveJSProperty", locator, "Locator", async (isNot, timeout) => {
238
return await locator._expect("to.have.property", { expressionArg: name, expectedValue: expected, isNot, timeout });
239
}, expected, options);
240
}
241
function toHaveRole(locator, expected, options) {
242
if (!(0, import_utils.isString)(expected))
243
throw new Error(`"role" argument in toHaveRole must be a string`);
244
return import_toMatchText.toMatchText.call(this, "toHaveRole", locator, "Locator", async (isNot, timeout) => {
245
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
246
return await locator._expect("to.have.role", { expectedText, isNot, timeout });
247
}, expected, options);
248
}
249
function toHaveText(locator, expected, options = {}) {
250
if (Array.isArray(expected)) {
251
return import_toEqual.toEqual.call(this, "toHaveText", locator, "Locator", async (isNot, timeout) => {
252
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected, { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
253
return await locator._expect("to.have.text.array", { expectedText, isNot, useInnerText: options?.useInnerText, timeout });
254
}, expected, options);
255
} else {
256
return import_toMatchText.toMatchText.call(this, "toHaveText", locator, "Locator", async (isNot, timeout) => {
257
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
258
return await locator._expect("to.have.text", { expectedText, isNot, useInnerText: options?.useInnerText, timeout });
259
}, expected, options);
260
}
261
}
262
function toHaveValue(locator, expected, options) {
263
return import_toMatchText.toMatchText.call(this, "toHaveValue", locator, "Locator", async (isNot, timeout) => {
264
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected]);
265
return await locator._expect("to.have.value", { expectedText, isNot, timeout });
266
}, expected, options);
267
}
268
function toHaveValues(locator, expected, options) {
269
return import_toEqual.toEqual.call(this, "toHaveValues", locator, "Locator", async (isNot, timeout) => {
270
const expectedText = (0, import_utils.serializeExpectedTextValues)(expected);
271
return await locator._expect("to.have.values", { expectedText, isNot, timeout });
272
}, expected, options);
273
}
274
function toHaveTitle(page, expected, options = {}) {
275
return import_toMatchText.toMatchText.call(this, "toHaveTitle", page, "Page", async (isNot, timeout) => {
276
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { normalizeWhiteSpace: true });
277
return await page.mainFrame()._expect("to.have.title", { expectedText, isNot, timeout });
278
}, expected, options);
279
}
280
function toHaveURL(page, expected, options) {
281
if (typeof expected === "function")
282
return import_toHaveURL.toHaveURLWithPredicate.call(this, page, expected, options);
283
const baseURL = page.context()._options.baseURL;
284
expected = typeof expected === "string" ? (0, import_utils.constructURLBasedOnBaseURL)(baseURL, expected) : expected;
285
return import_toMatchText.toMatchText.call(this, "toHaveURL", page, "Page", async (isNot, timeout) => {
286
const expectedText = (0, import_utils.serializeExpectedTextValues)([expected], { ignoreCase: options?.ignoreCase });
287
return await page.mainFrame()._expect("to.have.url", { expectedText, isNot, timeout });
288
}, expected, options);
289
}
290
async function toBeOK(response) {
291
const matcherName = "toBeOK";
292
(0, import_util.expectTypes)(response, ["APIResponse"], matcherName);
293
const contentType = response.headers()["content-type"];
294
const isTextEncoding = contentType && (0, import_utils.isTextualMimeType)(contentType);
295
const [log, text] = this.isNot === response.ok() ? await Promise.all([
296
response._fetchLog(),
297
isTextEncoding ? response.text() : null
298
]) : [];
299
const message = () => (0, import_utils.formatMatcherMessage)(this.utils, {
300
isNot: this.isNot,
301
promise: this.promise,
302
matcherName,
303
receiver: "response",
304
expectation: "",
305
log
306
}) + (text === null ? "" : `
307
Response text:
308
${import_utils2.colors.dim(text?.substring(0, 1e3) || "")}`);
309
const pass = response.ok();
310
return { message, pass };
311
}
312
async function toPass(callback, options = {}) {
313
const testInfo = (0, import_globals.currentTestInfo)();
314
const timeout = (0, import_config.takeFirst)(options.timeout, testInfo?._projectInternal.expect?.toPass?.timeout, 0);
315
const intervals = (0, import_config.takeFirst)(options.intervals, testInfo?._projectInternal.expect?.toPass?.intervals, [100, 250, 500, 1e3]);
316
const { deadline, timeoutMessage } = testInfo ? testInfo._deadlineForMatcher(timeout) : import_testInfo.TestInfoImpl._defaultDeadlineForMatcher(timeout);
317
const result = await (0, import_utils.pollAgainstDeadline)(async () => {
318
if (testInfo && (0, import_globals.currentTestInfo)() !== testInfo)
319
return { continuePolling: false, result: void 0 };
320
try {
321
await callback();
322
return { continuePolling: !!this.isNot, result: void 0 };
323
} catch (e) {
324
return { continuePolling: !this.isNot, result: e };
325
}
326
}, deadline, intervals);
327
if (result.timedOut) {
328
const message = result.result ? [
329
result.result.message,
330
"",
331
`Call Log:`,
332
`- ${timeoutMessage}`
333
].join("\n") : timeoutMessage;
334
return { message: () => message, pass: !!this.isNot };
335
}
336
return { pass: !this.isNot, message: () => "" };
337
}
338
function computeMatcherTitleSuffix(matcherName, receiver, args) {
339
if (matcherName === "toHaveScreenshot") {
340
const title = (0, import_toMatchSnapshot.toHaveScreenshotStepTitle)(...args);
341
return { short: title ? `(${title})` : "" };
342
}
343
if (receiver && typeof receiver === "object" && receiver.constructor?.name === "Locator") {
344
try {
345
return { long: " " + (0, import_utils.asLocatorDescription)("javascript", receiver._selector) };
346
} catch {
347
}
348
}
349
return {};
350
}
351
// Annotate the CommonJS export names for ESM import in node:
352
0 && (module.exports = {
353
computeMatcherTitleSuffix,
354
toBeAttached,
355
toBeChecked,
356
toBeDisabled,
357
toBeEditable,
358
toBeEmpty,
359
toBeEnabled,
360
toBeFocused,
361
toBeHidden,
362
toBeInViewport,
363
toBeOK,
364
toBeVisible,
365
toContainClass,
366
toContainText,
367
toHaveAccessibleDescription,
368
toHaveAccessibleErrorMessage,
369
toHaveAccessibleName,
370
toHaveAttribute,
371
toHaveCSS,
372
toHaveClass,
373
toHaveCount,
374
toHaveId,
375
toHaveJSProperty,
376
toHaveRole,
377
toHaveText,
378
toHaveTitle,
379
toHaveURL,
380
toHaveValue,
381
toHaveValues,
382
toPass
383
});
384

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button