1+ import { zoneSymbol } from '../../lib/common/utils' ;
2+ var defineProperty = Object [ zoneSymbol ( 'defineProperty' ) ] || Object . defineProperty ;
3+
14describe ( 'longStackTraceZone' , function ( ) {
2- let log ;
5+ let log : Error [ ] ;
36 let lstz : Zone ;
47
58 beforeEach ( function ( ) {
@@ -8,7 +11,7 @@ describe('longStackTraceZone', function () {
811 onHandleError : ( parentZoneDelegate : ZoneDelegate , currentZone : Zone , targetZone : Zone ,
912 error : any ) : boolean => {
1013 parentZoneDelegate . handleError ( targetZone , error ) ;
11- log . push ( error . stack ) ;
14+ log . push ( error ) ;
1215 return false ;
1316 }
1417 } ) ;
@@ -22,7 +25,7 @@ describe('longStackTraceZone', function () {
2225 setTimeout ( function ( ) {
2326 setTimeout ( function ( ) {
2427 try {
25- expect ( log [ 0 ] . split ( 'Elapsed: ' ) . length ) . toBe ( 3 ) ;
28+ expect ( log [ 0 ] . stack . split ( 'Elapsed: ' ) . length ) . toBe ( 3 ) ;
2629 done ( ) ;
2730 } catch ( e ) {
2831 expect ( e ) . toBe ( null ) ;
@@ -34,6 +37,26 @@ describe('longStackTraceZone', function () {
3437 } ) ;
3538 } ) ;
3639
40+ it ( 'should produce a long stack trace even if stack setter throws' , ( done ) => {
41+ let wasStackAssigne = false ;
42+ let error = new Error ( 'Expected error' ) ;
43+ defineProperty ( error , 'stack' , {
44+ configurable : false ,
45+ get : ( ) => 'someStackTrace' ,
46+ set : ( v ) => {
47+ throw new Error ( 'no writes' ) ;
48+ }
49+ } ) ;
50+ lstz . run ( ( ) => {
51+ setTimeout ( ( ) => { throw error ; } ) ;
52+ } ) ;
53+ setTimeout ( ( ) => {
54+ var e = log [ 0 ] ;
55+ expect ( ( e as any ) . longStack ) . toBeTruthy ( ) ;
56+ done ( ) ;
57+ } ) ;
58+ } ) ;
59+
3760 it ( 'should produce long stack traces when reject in promise' , function ( done ) {
3861 lstz . runGuarded ( function ( ) {
3962 setTimeout ( function ( ) {
@@ -48,7 +71,7 @@ describe('longStackTraceZone', function () {
4871 } ) ;
4972 setTimeout ( function ( ) {
5073 try {
51- expect ( log [ 0 ] . split ( 'Elapsed: ' ) . length ) . toBe ( 5 ) ;
74+ expect ( log [ 0 ] . stack . split ( 'Elapsed: ' ) . length ) . toBe ( 5 ) ;
5275 done ( ) ;
5376 } catch ( e ) {
5477 expect ( e ) . toBe ( null ) ;
0 commit comments