@@ -1506,6 +1506,24 @@ 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
+
1509
1527
it ( 'should match headers if specified' , function ( ) {
1510
1528
hb . when ( 'GET' , '/url' , null , { 'X' : 'val1' } ) . respond ( 201 , 'content1' ) ;
1511
1529
hb . when ( 'GET' , '/url' , null , { 'X' : 'val2' } ) . respond ( 202 , 'content2' ) ;
@@ -2833,6 +2851,24 @@ describe('ngMockE2E', function() {
2833
2851
} ) . toThrowError ( 'Unexpected request: GET /some\nNo more request expected' ) ;
2834
2852
} ) ;
2835
2853
2854
+ it ( 'should throw error when expectation fails - without error callback' , function ( ) {
2855
+ expect ( function ( ) {
2856
+ hb . expectPOST ( '/some' , { foo : 1 } ) . respond ( { } ) ;
2857
+ $http . post ( '/some' , { foo : 2 } ) . then ( noop ) ;
2858
+
2859
+ hb . flush ( ) ;
2860
+ } ) . 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 / ) ;
2861
+ } ) ;
2862
+
2863
+ it ( 'should throw error when unexpected request - with error callback' , function ( ) {
2864
+ expect ( function ( ) {
2865
+ hb . expectPOST ( '/some' , { foo : 1 } ) . respond ( { } ) ;
2866
+ $http . post ( '/some' , { foo : 2 } ) . then ( noop , noop ) ;
2867
+
2868
+ hb . flush ( ) ;
2869
+ } ) . 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 / ) ;
2870
+ } ) ;
2871
+
2836
2872
2837
2873
describe ( 'passThrough()' , function ( ) {
2838
2874
it ( 'should delegate requests to the real backend when passThrough is invoked' , function ( ) {
0 commit comments