2025-07-16 22:29:28 +08:00
|
|
|
"use strict";
|
|
|
|
|
2025-07-02 20:10:54 +08:00
|
|
|
const regexEscape = require("./regexEscape");
|
2023-05-10 02:58:57 +08:00
|
|
|
|
|
|
|
// These expect* methods are necessary because 'source' contains the code for this test file, which will always contain the string
|
|
|
|
// being tested for, so we have to use the "DO NOT MATCH BELOW..." technique to exclude the actual testing code from the test.
|
|
|
|
// Place your jest 'expect' calls below a line containing the DO NOT MATCH BELOW... string constructed below. See other tests for examples.
|
|
|
|
|
2023-05-10 06:13:20 +08:00
|
|
|
// Break up the match string so we don't match it in these expect* functions either.
|
2023-05-10 02:58:57 +08:00
|
|
|
const doNotMatch = ["DO", "NOT", "MATCH", "BELOW", "THIS", "LINE"].join(" ");
|
|
|
|
|
2025-04-22 20:42:33 +08:00
|
|
|
/**
|
|
|
|
* @param {string} source value
|
|
|
|
* @param {string} str string for searching
|
|
|
|
*/
|
2023-05-10 02:58:57 +08:00
|
|
|
function expectSourceToContain(source, str) {
|
2024-07-31 10:39:30 +08:00
|
|
|
expect(source).toMatch(new RegExp(`${regexEscape(str)}.*${doNotMatch}`, "s"));
|
2023-05-10 02:58:57 +08:00
|
|
|
}
|
2025-04-22 20:42:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} source value
|
|
|
|
* @param {RegExp} regexStr regexp
|
|
|
|
*/
|
2023-05-10 02:58:57 +08:00
|
|
|
function expectSourceToMatch(source, regexStr) {
|
2024-07-31 10:39:30 +08:00
|
|
|
expect(source).toMatch(new RegExp(`${regexStr}.*${doNotMatch}`, "s"));
|
2023-05-10 02:58:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { expectSourceToContain, expectSourceToMatch };
|