Skip to content

Commit f53c614

Browse files
committed
chore: add jsdoc and improve argument handling
1 parent 480b502 commit f53c614

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test/helpers/playwright-custom-expects.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@
33
const path = require("path");
44
const { test, expect, mergeExpects } = require("@playwright/test");
55

6-
// TODO: clean and refactor it, check with the team about bypassing the undefined
6+
/**
7+
* Custom Playwright matcher to match a snapshot with an array.
8+
*
9+
* @function toMatchSnapshotWithArray
10+
* @memberof expect
11+
* @instance
12+
* @async
13+
* @param {Array} received - The received array that will be serialized and compared to the snapshot.
14+
* @param {string} name - The name of the snapshot file.
15+
* @returns {Promise<{message: function, pass: boolean, name: string, expected: Array, actual: *}>} - The result of the matcher.
16+
* @throws {Error} If the received value is not an array.
17+
*/
718
const toMatchSnapshotWithArray = expect.extend({
819
async toMatchSnapshotWithArray(received, name) {
9-
if (!Array.isArray(received)) {
10-
throw new Error("Expected argument to be an array.");
20+
// find a better way or modify error message
21+
if (!["object", "number", "array", "string"].includes(typeof received)) {
22+
throw new Error(
23+
`Expected argument to be an object. but received ${typeof received}.`,
24+
);
1125
}
1226

1327
const assertionName = "toMatchSnapshotWithArray";

0 commit comments

Comments
 (0)