@@ -12,36 +12,38 @@ let TestAdapter = QUnitAdapter.extend({
1212
1313let noop = ( ) => { } ;
1414
15- function reset ( origTestAdapter , origLoggerError ) {
15+ let cleanup = ( origTestAdapter , origLoggerError ) => {
1616 // Cleanup the test adapter and restore the original.
17- Ember . run ( ( ) => {
17+ return Ember . run ( ( ) => {
1818 Ember . Test . adapter . destroy ( ) ;
1919 Ember . Test . adapter = origTestAdapter ;
2020 Ember . Logger . error = origLoggerError ;
2121 } ) ;
22- }
22+ } ;
2323
24- function handleError ( syncErrorInCallback ) {
25- let error = syncErrorInCallback || Ember . Test . adapter . lastError ;
26- let isEmberError = error instanceof Ember . Error ;
27- let matches = Boolean ( isEmberError && checkMatcher ( error . message , matcher ) ) ;
24+ let handleError = ( context , error , matcher , isProductionBuild ) => {
25+ let isEmberError = error instanceof Ember . Error ;
26+ let matches = Boolean ( isEmberError && checkMatcher ( error . message , matcher ) ) ;
27+ let errObj = { } ;
2828
29- if ( isProductionBuild ) {
30- this . pushResult ( {
31- result : true ,
32- actual : null ,
33- expected : null ,
34- message : 'Assertions are disabled in production builds.'
35- } ) ;
36- } else {
37- this . pushResult ( {
38- result : isEmberError && matches ,
39- actual : error && error . message ,
40- expected : matcher ,
41- message : matcher ? 'Ember.assert matched specific message' : 'Ember.assert called with any message'
42- } ) ;
43- }
44- }
29+ if ( isProductionBuild ) {
30+ errObj = {
31+ result : true ,
32+ actual : null ,
33+ expected : null ,
34+ message : 'Assertions are disabled in production builds.'
35+ } ;
36+ } else {
37+ errObj = {
38+ result : isEmberError && matches ,
39+ actual : error && error . message ,
40+ expected : matcher ,
41+ message : matcher ? 'Ember.assert matched specific message' : 'Ember.assert called with any message'
42+ } ;
43+ }
44+
45+ context . pushResult ( errObj ) ;
46+ } ;
4547
4648export default function ( ) {
4749 let isProductionBuild = ( function ( ) {
@@ -71,13 +73,18 @@ export default function() {
7173 error = e ;
7274 }
7375
74- if ( result && typeof result . then === 'function' ) {
76+ if ( error ) {
77+ handleError ( this , error , matcher , isProductionBuild ) ;
78+ } else if ( Ember . Test . adapter . lastError ) {
79+ handleError ( this , Ember . Test . adapter . lastError , matcher , isProductionBuild ) ;
80+ } else if ( result && typeof result === 'object' && result !== null && typeof result . then === 'function' ) {
7581 return result
76- . then ( null , ( ) => handleError ( error ) )
82+ . then ( null , ( ) => handleError ( this , error , matcher , isProductionBuild ) )
7783 . finally ( ( ) => cleanup ( origTestAdapter , origLoggerError ) ) ;
84+ } else {
85+ handleError ( this , null , matcher , null ) ;
7886 }
79-
8087
81- cleanup ( origTestAdapter , origLoggerError ) ;
88+ return cleanup ( origTestAdapter , origLoggerError ) ;
8289 } ;
8390}
0 commit comments