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