@@ -69,12 +69,36 @@ export function createExpectPoll(expect: ExpectStatic): ExpectStatic['poll'] {
6969 let timeoutId : any
7070 let lastError : any
7171 const { setTimeout, clearTimeout } = getSafeTimers ( )
72+ const rejectWithCause = ( error : any ) => {
73+ if ( error . cause == null ) {
74+ error . cause = new Error ( 'Matcher did not succeed in time.' )
75+ }
76+ reject (
77+ copyStackTrace (
78+ error ,
79+ STACK_TRACE_ERROR ,
80+ ) ,
81+ )
82+ }
7283 const check = async ( ) => {
7384 try {
7485 chai . util . flag ( assertion , '_name' , key )
7586 const obj = await fn ( )
7687 chai . util . flag ( assertion , 'object' , obj )
77- resolve ( await assertionFunction . call ( assertion , ...args ) )
88+ try {
89+ resolve ( await assertionFunction . call ( assertion , ...args ) )
90+ }
91+ catch ( err ) {
92+ if ( chai . util . flag ( assertion , '_poll.assert_once' ) ) {
93+ clearTimeout ( intervalId )
94+ clearTimeout ( timeoutId )
95+
96+ rejectWithCause ( err )
97+ }
98+ else {
99+ throw err
100+ }
101+ }
78102 clearTimeout ( intervalId )
79103 clearTimeout ( timeoutId )
80104 }
@@ -88,17 +112,6 @@ export function createExpectPoll(expect: ExpectStatic): ExpectStatic['poll'] {
88112 timeoutId = setTimeout ( ( ) => {
89113 clearTimeout ( intervalId )
90114 chai . util . flag ( assertion , '_isLastPollAttempt' , true )
91- const rejectWithCause = ( error : any ) => {
92- if ( error . cause == null ) {
93- error . cause = new Error ( 'Matcher did not succeed in time.' )
94- }
95- reject (
96- copyStackTrace (
97- error ,
98- STACK_TRACE_ERROR ,
99- ) ,
100- )
101- }
102115 check ( )
103116 . then ( ( ) => rejectWithCause ( lastError ) )
104117 . catch ( e => rejectWithCause ( e ) )
0 commit comments