Skip to content

Commit 3580f25

Browse files
authoredOct 3, 2023
fix: use defineProperty on the error object instead of setting the message directly (#1268)
Co-authored-by: Julien Wajsberg <felash@gmail.com> Fixes #1259
1 parent 2c57055 commit 3580f25

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed
 

‎src/__tests__/wait-for.js

+25
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@ test('timeout logs a pretty DOM', async () => {
148148
`)
149149
})
150150

151+
test("timeout doesn't error on DOMExceptions", async () => {
152+
renderIntoDocument(`<div id="pretty">how pretty</div>`)
153+
const error = await waitFor(
154+
() => {
155+
throw new DOMException('nooooooo!')
156+
},
157+
{timeout: 1},
158+
).catch(e => e)
159+
expect(error.message).toMatchInlineSnapshot(`
160+
nooooooo!
161+
162+
Ignored nodes: comments, script, style
163+
<html>
164+
<head />
165+
<body>
166+
<div
167+
id="pretty"
168+
>
169+
how pretty
170+
</div>
171+
</body>
172+
</html>
173+
`)
174+
})
175+
151176
test('should delegate to config.getElementError', async () => {
152177
const elementError = new Error('Custom element error')
153178
const getElementError = jest.fn().mockImplementation(() => elementError)

‎src/wait-for.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ function waitFor(
2424
stackTraceError,
2525
interval = 50,
2626
onTimeout = error => {
27-
error.message = getConfig().getElementError(
28-
error.message,
29-
container,
30-
).message
27+
Object.defineProperty(error, 'message', {
28+
value: getConfig().getElementError(error.message, container).message,
29+
})
3130
return error
3231
},
3332
mutationObserverOptions = {

0 commit comments

Comments
 (0)
Please sign in to comment.