File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -182,13 +182,14 @@ function wrapAssertions(callbacks) {
182182coreAssertThrowsErrorArg = err ;
183183}
184184
185+ let maybePromise ;
185186const test = ( fn , stack ) => {
186187let actual ;
187188let threw = false ;
188189try {
189190coreAssert . throws ( ( ) => {
190191try {
191- fn ( ) ;
192+ maybePromise = fn ( ) ;
192193} catch ( err ) {
193194actual = err ;
194195threw = true ;
@@ -208,7 +209,7 @@ function wrapAssertions(callbacks) {
208209}
209210} ;
210211
211- if ( promise ) {
212+ const handlePromise = promise => {
212213// Record stack before it gets lost in the promise chain.
213214const stack = getStack ( ) ;
214215const intermediate = promise . then ( value => {
@@ -222,13 +223,25 @@ function wrapAssertions(callbacks) {
222223pending ( this , intermediate ) ;
223224// Don't reject the returned promise, even if the assertion fails.
224225return intermediate . catch ( noop ) ;
226+ } ;
227+
228+ if ( promise ) {
229+ return handlePromise . call ( this , promise ) ;
225230}
226231
227232try {
228233const retval = test ( fn ) ;
229234pass ( this ) ;
230235return retval ;
231236} catch ( err ) {
237+ if ( maybePromise ) {
238+ if ( isPromise ( maybePromise ) ) {
239+ return handlePromise . call ( this , maybePromise ) ;
240+ }
241+ if ( isObservable ( maybePromise ) ) {
242+ return handlePromise . call ( this , observableToPromise ( maybePromise ) ) ;
243+ }
244+ }
232245fail ( this , err ) ;
233246}
234247} ,
Original file line number Diff line number Diff line change @@ -678,6 +678,17 @@ test('.throws() returns the rejection reason of promise', t => {
678678} ) ;
679679} ) ;
680680
681+ test ( '.throws() returns the rejection reason of function that return rejected `Promise`' , t => {
682+ const expected = new Error ( ) ;
683+
684+ return assertions . throws ( ( ) => {
685+ return Promise . reject ( expected ) ;
686+ } ) . then ( actual => {
687+ t . is ( actual , expected ) ;
688+ t . end ( ) ;
689+ } ) ;
690+ } ) ;
691+
681692test ( '.throws() fails if passed a bad value' , t => {
682693failsWith ( t , ( ) => {
683694assertions . throws ( 'not a function' ) ;
You can’t perform that action at this time.
0 commit comments