@@ -1506,6 +1506,42 @@ describe('ngMock', function() {
1506
1506
} ) ;
1507
1507
1508
1508
1509
+ it ( 'should throw error when expectation fails' , function ( ) {
1510
+ expect ( function ( ) {
1511
+ hb . expectPOST ( '/some' , { foo : 1 } ) . respond ( { } ) ;
1512
+ hb ( 'POST' , '/some' , { foo : 2 } , callback ) ;
1513
+ hb . flush ( ) ;
1514
+ } ) . toThrowError ( / ^ E x p e c t e d P O S T \/ s o m e w i t h d i f f e r e n t d a t a / ) ;
1515
+ } ) ;
1516
+
1517
+
1518
+ it ( 'should throw error when expectation about headers fails' , function ( ) {
1519
+ expect ( function ( ) {
1520
+ hb . expectPOST ( '/some' , { foo : 1 } , { X : 'val1' } ) . respond ( { } ) ;
1521
+ hb ( 'POST' , '/some' , { foo : 1 } , callback , { X : 'val2' } ) ;
1522
+ hb . flush ( ) ;
1523
+ } ) . toThrowError ( / ^ E x p e c t e d P O S T \/ s o m e w i t h d i f f e r e n t h e a d e r s / ) ;
1524
+ } ) ;
1525
+
1526
+
1527
+ it ( 'should throw error about data when expectations about both data and headers fail' , function ( ) {
1528
+ expect ( function ( ) {
1529
+ hb . expectPOST ( '/some' , { foo : 1 } , { X : 'val1' } ) . respond ( { } ) ;
1530
+ hb ( 'POST' , '/some' , { foo : 2 } , callback , { X : 'val2' } ) ;
1531
+ hb . flush ( ) ;
1532
+ } ) . toThrowError ( / ^ E x p e c t e d P O S T \/ s o m e w i t h d i f f e r e n t d a t a / ) ;
1533
+ } ) ;
1534
+
1535
+
1536
+ it ( 'should throw error when response is not defined for a backend definition' , function ( ) {
1537
+ expect ( function ( ) {
1538
+ hb . whenGET ( '/some' ) ; // no .respond(...) !
1539
+ hb ( 'GET' , '/some' , null , callback ) ;
1540
+ hb . flush ( ) ;
1541
+ } ) . toThrowError ( 'No response defined !' ) ;
1542
+ } ) ;
1543
+
1544
+
1509
1545
it ( 'should match headers if specified' , function ( ) {
1510
1546
hb . when ( 'GET' , '/url' , null , { 'X' : 'val1' } ) . respond ( 201 , 'content1' ) ;
1511
1547
hb . when ( 'GET' , '/url' , null , { 'X' : 'val2' } ) . respond ( 202 , 'content2' ) ;
@@ -2833,6 +2869,24 @@ describe('ngMockE2E', function() {
2833
2869
} ) . toThrowError ( 'Unexpected request: GET /some\nNo more request expected' ) ;
2834
2870
} ) ;
2835
2871
2872
+ it ( 'should throw error when expectation fails - without error callback' , function ( ) {
2873
+ expect ( function ( ) {
2874
+ hb . expectPOST ( '/some' , { foo : 1 } ) . respond ( { } ) ;
2875
+ $http . post ( '/some' , { foo : 2 } ) . then ( noop ) ;
2876
+
2877
+ hb . flush ( ) ;
2878
+ } ) . toThrowError ( / ^ E x p e c t e d P O S T \/ s o m e w i t h d i f f e r e n t d a t a / ) ;
2879
+ } ) ;
2880
+
2881
+ it ( 'should throw error when unexpected request - with error callback' , function ( ) {
2882
+ expect ( function ( ) {
2883
+ hb . expectPOST ( '/some' , { foo : 1 } ) . respond ( { } ) ;
2884
+ $http . post ( '/some' , { foo : 2 } ) . then ( noop , noop ) ;
2885
+
2886
+ hb . flush ( ) ;
2887
+ } ) . toThrowError ( / ^ E x p e c t e d P O S T \/ s o m e w i t h d i f f e r e n t d a t a / ) ;
2888
+ } ) ;
2889
+
2836
2890
2837
2891
describe ( 'passThrough()' , function ( ) {
2838
2892
it ( 'should delegate requests to the real backend when passThrough is invoked' , function ( ) {
0 commit comments