@@ -51,59 +51,47 @@ function asyncTest(testFunc) {
51
51
assert . throwsAsync = function ( expectedErrorConstructor , func , message ) {
52
52
return new Promise ( function ( resolve ) {
53
53
var expectedName = expectedErrorConstructor . name ;
54
+ var expectation = "Expected a " + expectedName + " to be thrown asynchronously" ;
54
55
var fail = function ( detail ) {
55
56
if ( message === undefined ) {
56
57
throw new Test262Error ( detail ) ;
57
58
}
58
59
throw new Test262Error ( message + " " + detail ) ;
59
60
} ;
60
- var innerThenable ;
61
+ var res ;
61
62
if ( typeof func !== "function" ) {
62
63
fail ( "assert.throwsAsync called with an argument that is not a function" ) ;
63
64
}
64
65
try {
65
- innerThenable = func ( ) ;
66
+ res = func ( ) ;
66
67
} catch ( thrown ) {
67
- fail ( "Expected a " +
68
- expectedName +
69
- " to be thrown asynchronously but the function threw synchronously" ) ;
68
+ fail ( expectation + " but the function threw synchronously" ) ;
70
69
}
71
- if (
72
- innerThenable === null ||
73
- typeof innerThenable !== "object" ||
74
- typeof innerThenable . then !== "function"
75
- ) {
76
- fail ( "Expected to obtain a promise that would reject with a " +
77
- expectedName +
78
- " but result was not a thenable" ) ;
70
+ if ( res === null || typeof res !== "object" || typeof res . then !== "function" ) {
71
+ fail ( expectation + " but result was not a thenable" ) ;
79
72
}
80
73
81
74
try {
82
- resolve ( innerThenable . then (
75
+ resolve ( res . then (
83
76
function ( ) {
84
- fail ( "Expected a " +
85
- expectedName +
86
- " to be thrown asynchronously but no exception was thrown at all" ) ;
77
+ fail ( expectation + " but no exception was thrown at all" ) ;
87
78
} ,
88
79
function ( thrown ) {
89
80
var actualName ;
90
- if ( typeof thrown !== "object" || thrown === null ) {
91
- fail ( "Thrown value was not an object! ") ;
81
+ if ( thrown === null || typeof thrown !== "object" ) {
82
+ fail ( expectation + " but thrown value was not an object") ;
92
83
} else if ( thrown . constructor !== expectedErrorConstructor ) {
93
84
actualName = thrown . constructor . name ;
94
85
if ( expectedName === actualName ) {
95
- fail ( "Expected a " +
96
- expectedName +
86
+ fail ( expectation +
97
87
" but got a different error constructor with the same name" ) ;
98
88
}
99
- fail ( "Expected a " + expectedName + " but got a " + actualName ) ;
89
+ fail ( expectation + " but got a " + actualName ) ;
100
90
}
101
91
}
102
92
) ) ;
103
93
} catch ( thrown ) {
104
- fail ( "Expected a " +
105
- expectedName +
106
- " to be thrown asynchronously but .then threw synchronously" ) ;
94
+ fail ( expectation + " but .then threw synchronously" ) ;
107
95
}
108
96
} ) ;
109
97
} ;
0 commit comments