@@ -1090,7 +1090,7 @@ describe('ngMock', function() {
1090
1090
} ) ;
1091
1091
1092
1092
1093
- it ( 'should respond with first matched definition' , function ( ) {
1093
+ it ( 'should respond with first matched definition by default ' , function ( ) {
1094
1094
hb . when ( 'GET' , '/url1' ) . respond ( 200 , 'content' , { } ) ;
1095
1095
hb . when ( 'GET' , '/url1' ) . respond ( 201 , 'another' , { } ) ;
1096
1096
@@ -1106,25 +1106,76 @@ describe('ngMock', function() {
1106
1106
} ) ;
1107
1107
1108
1108
1109
- it ( 'should respond with latest matched definition when $httpBackend.matchLatestDefinition(true)' ,
1110
- function ( ) {
1111
- hb . matchLatestDefinition ( true ) ;
1109
+ describe ( 'matchLatestDefinitionEnabled()' , function ( ) {
1112
1110
1113
- hb . when ( 'GET' , '/url1' ) . respond ( 200 , 'content' , { } ) ;
1114
- hb . when ( 'GET' , '/url1' ) . respond ( 200 , 'middle' , { } ) ;
1115
- hb . when ( 'GET' , '/url1' ) . respond ( 201 , 'another' , { } ) ;
1111
+ it ( 'should be set to false by default' , function ( ) {
1112
+ expect ( hb . matchLatestDefinitionEnabled ( ) ) . toBe ( false ) ;
1113
+ } ) ;
1116
1114
1117
- callback . and . callFake ( function ( status , response ) {
1118
- expect ( status ) . toBe ( 201 ) ;
1119
- expect ( response ) . toBe ( 'another' ) ;
1120
- } ) ;
1121
1115
1122
- hb ( 'GET' , '/url1' , null , callback ) ;
1123
- expect ( callback ) . not . toHaveBeenCalled ( ) ;
1124
- hb . flush ( ) ;
1125
- expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1126
- }
1127
- ) ;
1116
+ it ( 'should allow to change the value' , function ( ) {
1117
+ hb . matchLatestDefinitionEnabled ( true ) ;
1118
+ expect ( hb . matchLatestDefinitionEnabled ( ) ) . toBe ( true ) ;
1119
+ } ) ;
1120
+
1121
+
1122
+ it ( 'should return the httpBackend when used as a setter' , function ( ) {
1123
+ expect ( hb . matchLatestDefinitionEnabled ( true ) ) . toBe ( hb ) ;
1124
+ } ) ;
1125
+
1126
+
1127
+ it ( 'should respond with the first matched definition when false' ,
1128
+ function ( ) {
1129
+ hb . matchLatestDefinitionEnabled ( false ) ;
1130
+
1131
+ hb . when ( 'GET' , '/url1' ) . respond ( 200 , 'content' , { } ) ;
1132
+ hb . when ( 'GET' , '/url1' ) . respond ( 201 , 'another' , { } ) ;
1133
+
1134
+ callback . and . callFake ( function ( status , response ) {
1135
+ expect ( status ) . toBe ( 200 ) ;
1136
+ expect ( response ) . toBe ( 'content' ) ;
1137
+ } ) ;
1138
+
1139
+ hb ( 'GET' , '/url1' , null , callback ) ;
1140
+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
1141
+ hb . flush ( ) ;
1142
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1143
+ }
1144
+ ) ;
1145
+
1146
+
1147
+ it ( 'should respond with latest matched definition when true' ,
1148
+ function ( ) {
1149
+ hb . matchLatestDefinitionEnabled ( true ) ;
1150
+
1151
+ hb . when ( 'GET' , '/url1' ) . respond ( 200 , 'match1' , { } ) ;
1152
+ hb . when ( 'GET' , '/url1' ) . respond ( 200 , 'match2' , { } ) ;
1153
+ hb . when ( 'GET' , '/url2' ) . respond ( 204 , 'nomatch' , { } ) ;
1154
+
1155
+ callback . and . callFake ( function ( status , response ) {
1156
+ expect ( status ) . toBe ( 200 ) ;
1157
+ expect ( response ) . toBe ( 'match2' ) ;
1158
+ } ) ;
1159
+
1160
+ hb ( 'GET' , '/url1' , null , callback ) ;
1161
+
1162
+ // Check if a newly added match is used
1163
+ hb . when ( 'GET' , '/url1' ) . respond ( 201 , 'match3' , { } ) ;
1164
+
1165
+ var callback2 = jasmine . createSpy ( ) ;
1166
+
1167
+ callback2 . and . callFake ( function ( status , response ) {
1168
+ expect ( status ) . toBe ( 201 ) ;
1169
+ expect ( response ) . toBe ( 'match3' ) ;
1170
+ } ) ;
1171
+
1172
+ hb ( 'GET' , '/url1' , null , callback2 ) ;
1173
+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
1174
+ hb . flush ( ) ;
1175
+ expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1176
+ }
1177
+ ) ;
1178
+ } ) ;
1128
1179
1129
1180
1130
1181
it ( 'should respond with a copy of the mock data' , function ( ) {
0 commit comments