Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. httpBackend.whenPOST('/myurl')
  2. .respond( 200,obj1 );
  3. httpBackend.expectPOST('/myurl')
  4.  
  5.  
  6. scope = $rootScope.$new();
  7. MainCtrl = $controller('MyCtrl', {
  8. $scope:scope
  9. });
  10.  
  11. it('scope.mymethod should work fine', function(){
  12.  
  13. httpBackend.flush()
  14.  
  15.  
  16. // verify size of array before calling the method
  17. expect(scope.myobjs.length).toEqual(2)
  18. // call the method
  19. scope.saveNewPage(myobj)
  20. // verify size of array after calling the method
  21. expect(scope.myobjs.length).toEqual(3)
  22.  
  23. })
  24.  
  25. function saveNewPage(p){
  26. console.log('Hello')
  27. $http.post('/myurl', {
  28. e:p.e, url:p.url, name:p.name
  29. }).then(function (response) {
  30. otherMethod(new Page(response.data.page))
  31. }, handleError);
  32. }
  33.  
  34. it('scope.saveNewPage should work fine', function(){
  35. var p=new Object(pages[0])
  36.  
  37. httpBackend.flush()
  38.  
  39. httpBackend.whenPOST('/myurl',{
  40. url:pages[0].url,
  41. existingPage:new Object(pages[0]),
  42. name:pages[0].name
  43. }).respond(200,{data:pages[0]})
  44. httpBackend.expectPOST('/myurl')
  45.  
  46. scope.saveNewPage(p)
  47.  
  48. httpBackend.flush()
  49.  
  50.  
  51. expect(scope.pages.length).toBe(3)
  52.  
  53.  
  54. })
  55.  
  56. it('scope.mymethod should work fine', function(){
  57. expect(scope.myobjs.length).toEqual(2)
  58. scope.saveNewPage(myobj)
  59. expect(scope.myobjs.length).toEqual(2)
  60.  
  61. httpBackend.flush()
  62. expect(scope.myobjs.length).toEqual(3)
  63. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement