Skip to content

Commit 18dd4ba

Browse files
committed
Updated the config flag based on the feedback
1 parent 87159f0 commit 18dd4ba

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/__tests__/wait-for.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ test('uses generic error if there was no last error', async () => {
3434
expect(result).toMatchInlineSnapshot(`[Error: Timed out in waitFor.]`)
3535
})
3636

37+
test('uses full stack error trace when showOriginalStackTrace present', async () => {
38+
const error = new Error('Throws the full stack trace')
39+
const result = await waitFor(
40+
() => {
41+
throw error
42+
},
43+
{timeout: 8, interval: 5, showOriginalStackTrace: true},
44+
).catch(e => e)
45+
expect(result).toBe(error)
46+
})
47+
3748
test('throws nice error if provided callback is not a function', () => {
3849
const {queryByTestId} = renderIntoDocument(`
3950
<div data-testid="div"></div>

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ let config = {
1616
asyncWrapper: cb => cb(),
1717
// default value for the `hidden` option in `ByRole` queries
1818
defaultHidden: false,
19+
//showOriginalStackTrace flag to show the full error stack traces for async errors
20+
showOriginalStackTrace: false,
1921

2022
// called when getBy* queries fail. (message, container) => Error
2123
getElementError(message, container) {

src/wait-for.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function waitFor(
1313
{
1414
container = getDocument(),
1515
timeout = getConfig().asyncUtilTimeout,
16+
showOriginalStackTrace = getConfig().showOriginalStackTrace,
1617
interval = 50,
1718
mutationObserverOptions = {
1819
subtree: true,
@@ -66,11 +67,13 @@ function waitFor(
6667
let error = timedOutError
6768
if (lastError) {
6869
error = lastError
69-
const userStackTrace = timedOutError.stack
70-
.split('\n')
71-
.slice(1)
72-
.join('\n')
73-
error.stack = `${error.stack.split('\n')[0]}\n${userStackTrace}`
70+
if (showOriginalStackTrace) {
71+
const userStackTrace = timedOutError.stack
72+
.split('\n')
73+
.slice(1)
74+
.join('\n')
75+
error.stack = `${error.stack.split('\n')[0]}\n${userStackTrace}`
76+
}
7477
}
7578
onDone(error, null)
7679
}

0 commit comments

Comments
 (0)