Skip to content

Commit 2df5e83

Browse files
committed
Test formatAsJSLiteral
1 parent b71962f commit 2df5e83

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Extension implements StringifyExtension {
121121
}
122122
}
123123

124-
function formatAsJSLiteral(value: string) {
124+
export function formatAsJSLiteral(value: string) {
125125
return `"${value.replace(/"/g, '\\"')}"`
126126
}
127127

src/test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {
77
type Step,
88
type UserFlow,
99
} from "@puppeteer/replay"
10-
import { Extension, RecorderPlugin, stringifySelector } from "."
10+
import {
11+
Extension,
12+
formatAsJSLiteral,
13+
RecorderPlugin,
14+
stringifySelector,
15+
} from "."
1116
import flow from "./fixtures/Example.json"
1217

1318
const extension = new Extension()
@@ -176,6 +181,20 @@ describe("Extension", () => {
176181
})
177182
})
178183

184+
describe("formatAsJSLiteral", () => {
185+
test("space", () => {
186+
expect(formatAsJSLiteral(" ")).toBe('" "')
187+
})
188+
189+
test("single quote", () => {
190+
expect(formatAsJSLiteral("'")).toBe('"\'"')
191+
})
192+
193+
test("double quote", () => {
194+
expect(formatAsJSLiteral('"')).toBe('"\\""')
195+
})
196+
})
197+
179198
describe("stringifySelector", () => {
180199
test("aria", () => {
181200
expect(stringifySelector("aria/Test")).toBe('screen.getByText("Test")')

0 commit comments

Comments
 (0)