@@ -23,7 +23,7 @@ test('can timeout after the given timeout time', async () => {
23
23
expect ( result ) . toBe ( error )
24
24
} )
25
25
26
- test ( 'uses generic error if there was no last error' , async ( ) => {
26
+ test ( 'if no error is thrown then throws a timeout error' , async ( ) => {
27
27
const result = await waitFor (
28
28
( ) => {
29
29
// eslint-disable-next-line no-throw-literal
@@ -34,6 +34,58 @@ test('uses generic error if there was no last error', async () => {
34
34
expect ( result ) . toMatchInlineSnapshot ( `[Error: Timed out in waitFor.]` )
35
35
} )
36
36
37
+ test ( 'if showOriginalStackTrace on a timeout error then the stack trace does not include this file' , async ( ) => {
38
+ const result = await waitFor (
39
+ ( ) => {
40
+ // eslint-disable-next-line no-throw-literal
41
+ throw undefined
42
+ } ,
43
+ { timeout : 8 , interval : 5 , showOriginalStackTrace : true } ,
44
+ ) . catch ( e => e )
45
+ expect ( result . stack ) . not . toMatch ( __dirname )
46
+ } )
47
+
48
+ test ( 'uses full stack error trace when showOriginalStackTrace present' , async ( ) => {
49
+ const error = new Error ( 'Throws the full stack trace' )
50
+ // even if the error is a TestingLibraryElementError
51
+ error . name = 'TestingLibraryElementError'
52
+ const originalStackTrace = error . stack
53
+ const result = await waitFor (
54
+ ( ) => {
55
+ throw error
56
+ } ,
57
+ { timeout : 8 , interval : 5 , showOriginalStackTrace : true } ,
58
+ ) . catch ( e => e )
59
+ expect ( result . stack ) . toBe ( originalStackTrace )
60
+ } )
61
+
62
+ test ( 'does not change the stack trace if the thrown error is not a TestingLibraryElementError' , async ( ) => {
63
+ const error = new Error ( 'Throws the full stack trace' )
64
+ const originalStackTrace = error . stack
65
+ const result = await waitFor (
66
+ ( ) => {
67
+ throw error
68
+ } ,
69
+ { timeout : 8 , interval : 5 } ,
70
+ ) . catch ( e => e )
71
+ expect ( result . stack ) . toBe ( originalStackTrace )
72
+ } )
73
+
74
+ test ( 'provides an improved stack trace if the thrown error is a TestingLibraryElementError' , async ( ) => {
75
+ const error = new Error ( 'Throws the full stack trace' )
76
+ error . name = 'TestingLibraryElementError'
77
+ const originalStackTrace = error . stack
78
+ const result = await waitFor (
79
+ ( ) => {
80
+ throw error
81
+ } ,
82
+ { timeout : 8 , interval : 5 } ,
83
+ ) . catch ( e => e )
84
+ // too hard to test that the stack trace is what we want it to be
85
+ // so we'll just make sure that it's not the same as the origianl
86
+ expect ( result . stack ) . not . toBe ( originalStackTrace )
87
+ } )
88
+
37
89
test ( 'throws nice error if provided callback is not a function' , ( ) => {
38
90
const { queryByTestId} = renderIntoDocument ( `
39
91
<div data-testid="div"></div>
0 commit comments