@@ -915,50 +915,67 @@ describe('ngMock', function() {
915
915
} ) . toThrow ( 'test message' ) ;
916
916
} ) ) ;
917
917
918
- describe ( 'error stack trace when called outside of spec context' , function ( ) {
919
- // - Chrome, Firefox, Edge, Opera give us the stack trace as soon as an Error is created
920
- // - IE10+, PhantomJS give us the stack trace only once the error is thrown
921
- // - IE9 does not provide stack traces
922
- var stackTraceSupported = ( function ( ) {
923
- var error = new Error ( ) ;
924
- if ( ! error . stack ) {
925
- try {
926
- throw error ;
927
- } catch ( e ) { }
928
- }
918
+ // - Chrome, Firefox, Edge, Opera give us the stack trace as soon as an Error is created
919
+ // - IE10+, PhantomJS give us the stack trace only once the error is thrown
920
+ // - IE9 does not provide stack traces
921
+ var stackTraceSupported = ( function ( ) {
922
+ var error = new Error ( ) ;
923
+ if ( ! error . stack ) {
924
+ try {
925
+ throw error ;
926
+ } catch ( e ) { }
927
+ }
929
928
930
- return ! ! error . stack ;
931
- } ) ( ) ;
929
+ return ! ! error . stack ;
930
+ } ) ( ) ;
932
931
933
- function testCaller ( ) {
932
+ function testInjectCaller ( ) {
933
+ var shouldThrow ;
934
+ var injectingCall = ( function internalInjectCaller ( ) {
934
935
return inject ( function ( ) {
935
- throw new Error ( ) ;
936
+ if ( shouldThrow )
937
+ throw new Error ( ) ;
936
938
} ) ;
937
- }
938
- var throwErrorFromInjectCallback = testCaller ( ) ;
939
+ } ) ( ) ;
940
+ injectingCall . setThrow = function ( value ) {
941
+ shouldThrow = value ;
942
+ } ;
943
+ return injectingCall ;
944
+ }
939
945
940
- if ( stackTraceSupported ) {
941
- describe ( 'on browsers supporting stack traces' , function ( ) {
942
- it ( 'should update thrown Error stack trace with inject call location' , function ( ) {
946
+ if ( ! stackTraceSupported ) {
947
+ describe ( 'on browsers not supporting stack traces' , function ( ) {
948
+ describe ( 'when called outside of test spec context' , function ( ) {
949
+ var injectingCall = testInjectCaller ( ) ;
950
+
951
+ it ( 'should not add stack trace information to thrown injection Error' , function ( ) {
952
+ injectingCall . setThrow ( true ) ;
943
953
try {
944
- throwErrorFromInjectCallback ( ) ;
954
+ injectingCall ( ) ;
945
955
} catch ( e ) {
946
- expect ( e . stack ) . toMatch ( 'testCaller' ) ;
956
+ expect ( e . stack ) . toBeUndefined ( ) ;
947
957
}
948
958
} ) ;
949
959
} ) ;
950
- } else {
951
- describe ( 'on browsers not supporting stack traces' , function ( ) {
952
- it ( 'should not add stack trace information to thrown Error' , function ( ) {
960
+ } ) ;
961
+ }
962
+
963
+ if ( stackTraceSupported ) {
964
+ describe ( 'on browsers supporting stack traces' , function ( ) {
965
+ describe ( 'when called outside of test spec context and initial inject callback invocation fails' , function ( ) {
966
+ var throwingInjectingCall = testInjectCaller ( ) ;
967
+ throwingInjectingCall . setThrow ( true ) ;
968
+
969
+ it ( 'should update thrown Error stack trace with inject call location' , function ( ) {
953
970
try {
954
- throwErrorFromInjectCallback ( ) ;
971
+ throwingInjectingCall ( ) ;
955
972
} catch ( e ) {
956
- expect ( e . stack ) . toBeUndefined ( ) ;
973
+ expect ( e . stack ) . toMatch ( 'testInjectCaller' ) ;
957
974
}
958
975
} ) ;
959
976
} ) ;
960
- }
961
- } ) ;
977
+ } ) ;
978
+ }
962
979
} ) ;
963
980
} ) ;
964
981
0 commit comments