@@ -941,6 +941,29 @@ describe('ngMock', function() {
941
941
} ) ;
942
942
943
943
944
+ it ( 'should match data object if specified' , function ( ) {
945
+ hb . when ( 'GET' , '/a/b' , { a : 1 , b : 2 } ) . respond ( 201 , 'content1' ) ;
946
+ hb . when ( 'GET' , '/a/b' ) . respond ( 202 , 'content2' ) ;
947
+
948
+ hb ( 'GET' , '/a/b' , '{"a":1,"b":2}' , function ( status , response ) {
949
+ expect ( status ) . toBe ( 201 ) ;
950
+ expect ( response ) . toBe ( 'content1' ) ;
951
+ } ) ;
952
+
953
+ hb ( 'GET' , '/a/b' , '{"b":2,"a":1}' , function ( status , response ) {
954
+ expect ( status ) . toBe ( 201 ) ;
955
+ expect ( response ) . toBe ( 'content1' ) ;
956
+ } ) ;
957
+
958
+ hb ( 'GET' , '/a/b' , null , function ( status , response ) {
959
+ expect ( status ) . toBe ( 202 ) ;
960
+ expect ( response ) . toBe ( 'content2' ) ;
961
+ } ) ;
962
+
963
+ hb . flush ( ) ;
964
+ } ) ;
965
+
966
+
944
967
it ( 'should match only method' , function ( ) {
945
968
hb . when ( 'GET' ) . respond ( 202 , 'c' ) ;
946
969
callback . andCallFake ( function ( status , response ) {
@@ -1072,6 +1095,32 @@ describe('ngMock', function() {
1072
1095
} ) ;
1073
1096
1074
1097
1098
+ it ( 'should not throw an exception when parsed body is equal to expected body object' , function ( ) {
1099
+ hb . when ( 'GET' ) . respond ( 200 , '' , { } ) ;
1100
+
1101
+ hb . expect ( 'GET' , '/match' , { a : 1 , b : 2 } ) ;
1102
+ expect ( function ( ) {
1103
+ hb ( 'GET' , '/match' , '{"a":1,"b":2}' , noop , { } ) ;
1104
+ } ) . not . toThrow ( ) ;
1105
+
1106
+ hb . expect ( 'GET' , '/match' , { a : 1 , b : 2 } ) ;
1107
+ expect ( function ( ) {
1108
+ hb ( 'GET' , '/match' , '{"b":2,"a":1}' , noop , { } ) ;
1109
+ } ) . not . toThrow ( ) ;
1110
+ } ) ;
1111
+
1112
+
1113
+ it ( 'should throw exception when only parsed body differs from expected body object' , function ( ) {
1114
+ hb . when ( 'GET' ) . respond ( 200 , '' , { } ) ;
1115
+ hb . expect ( 'GET' , '/match' , { a : 1 , b : 2 } ) ;
1116
+
1117
+ expect ( function ( ) {
1118
+ hb ( 'GET' , '/match' , '{"a":1,"b":3}' , noop , { } ) ;
1119
+ } ) . toThrow ( 'Expected GET /match with different data\n' +
1120
+ 'EXPECTED: {"a":1,"b":2}\nGOT: {"a":1,"b":3}' ) ;
1121
+ } ) ;
1122
+
1123
+
1075
1124
it ( "should use when's respond() when no expect() respond is defined" , function ( ) {
1076
1125
callback . andCallFake ( function ( status , response ) {
1077
1126
expect ( status ) . toBe ( 201 ) ;
0 commit comments