Skip to content

Commit 4db8b74

Browse files
authored
fix: allow double quotes in selector (#16)
1 parent cc38bce commit 4db8b74

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/index.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ Object.keys(queries).forEach(queryName => {
3838
})
3939

4040
export const within = async sel => {
41+
const sanitizedSel = sel.replace(/"/g, "'")
4142
await ClientFunction(
4243
new Function(
4344
`
44-
const elem = document.querySelector("${sel}");
45-
window.TestCafeTestingLibrary["within_${sel}"] = DomTestingLibrary.within(elem);
45+
const elem = document.querySelector("${sanitizedSel}");
46+
window.TestCafeTestingLibrary["within_${sanitizedSel}"] = DomTestingLibrary.within(elem);
4647
4748
`,
4849
),
@@ -52,21 +53,10 @@ export const within = async sel => {
5253
Object.keys(queries).forEach(queryName => {
5354
container[queryName] = Selector(
5455
new Function(
55-
`return window.TestCafeTestingLibrary["within_${sel}"].${queryName}(...arguments)`,
56+
`return window.TestCafeTestingLibrary["within_${sanitizedSel}"].${queryName}(...arguments)`,
5657
),
5758
)
5859
})
5960

6061
return container
61-
// const container = {}
62-
63-
// Object.keys(queries).forEach(queryName => {
64-
// container[queryName] = Selector(
65-
// new Function(
66-
// `return DomTestingLibrary.within(document.querySelector("${sel}")).${queryName}(...arguments)`,
67-
// ),
68-
// )
69-
// })
70-
71-
// return container
7262
}

tests/testcafe/within.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ test("queryByPlaceholder doesn't find anything", async t => {
1818

1919
await t.expect(queryByPlaceholderText('Placeholder Text').exists).notOk()
2020
})
21+
22+
test('quotes in selector', async t => {
23+
const {getByText} = await within('div[id="nested"]')
24+
25+
await t
26+
.click(getByText('Button Text'))
27+
.expect(Selector('button').withExactText('Button Clicked').exists)
28+
.ok()
29+
})

0 commit comments

Comments
 (0)