Skip to content

Commit c0ee359

Browse files
committed
test: preserveStrings utility function
1 parent 3520d01 commit c0ee359

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
2+
import generateRandomString from "./generateRandomString";
3+
import { preserveStrings, restoreStrings } from "./string-preservation";
4+
5+
jest.mock("./generateRandomString");
6+
7+
describe("preserveStrings", () => {
8+
beforeEach(() => {
9+
jest.resetAllMocks();
10+
});
11+
12+
it("should replace string values with placeholders and return the mapping of replacements", () => {
13+
(generateRandomString as jest.Mock).mockReturnValueOnce("RANDOM_GENERATED_STRING");
14+
15+
const code = `
16+
console.log({
17+
description: "Initiates the process for resetting a user's password by sending a reset link to their registered email",
18+
});
19+
`;
20+
21+
const output = preserveStrings(code);
22+
expect(output).toStrictEqual({
23+
output: `
24+
console.log({
25+
description: <@~RANDOM_GENERATED_STRING~@>,
26+
});
27+
`,
28+
replacements: {
29+
RANDOM_GENERATED_STRING: '"Initiates the process for resetting a user\'s password by sending a reset link to their registered email"',
30+
},
31+
});
32+
});
33+
});
34+
35+
describe("restoreStrings", () => {
36+
it("should ...", () => {
37+
expect(typeof restoreStrings).toBe("function");
38+
});
39+
});

0 commit comments

Comments
 (0)