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