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