@@ -1506,6 +1506,33 @@ 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 when expectation about both data and headers fails' , 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 / ) ;
1533
+ } ) ;
1534
+
1535
+
1509
1536
it ( 'should match headers if specified' , function ( ) {
1510
1537
hb . when ( 'GET' , '/url' , null , { 'X' : 'val1' } ) . respond ( 201 , 'content1' ) ;
1511
1538
hb . when ( 'GET' , '/url' , null , { 'X' : 'val2' } ) . respond ( 202 , 'content2' ) ;
@@ -2833,6 +2860,24 @@ describe('ngMockE2E', function() {
2833
2860
} ) . toThrowError ( 'Unexpected request: GET /some\nNo more request expected' ) ;
2834
2861
} ) ;
2835
2862
2863
+ it ( 'should throw error when expectation fails - without error callback' , function ( ) {
2864
+ expect ( function ( ) {
2865
+ hb . expectPOST ( '/some' , { foo : 1 } ) . respond ( { } ) ;
2866
+ $http . post ( '/some' , { foo : 2 } ) . then ( 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
+
2872
+ it ( 'should throw error when unexpected request - with error callback' , function ( ) {
2873
+ expect ( function ( ) {
2874
+ hb . expectPOST ( '/some' , { foo : 1 } ) . respond ( { } ) ;
2875
+ $http . post ( '/some' , { foo : 2 } ) . then ( noop , 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
+
2836
2881
2837
2882
describe ( 'passThrough()' , function ( ) {
2838
2883
it ( 'should delegate requests to the real backend when passThrough is invoked' , function ( ) {
0 commit comments