Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Controller: TopologyCtrl', function () {
  2.     beforeEach(angular.mock.module('myApp'));
  3.     var scope, httpBackend, Restangular, createController;
  4.     beforeEach(module(function ($urlRouterProvider) {
  5.         $urlRouterProvider.deferIntercept();
  6.     }));
  7.  
  8.     beforeEach(inject(function (_MyService_, $controller, $rootScope, _$httpBackend_, _Restangular_, _$q_) {
  9.         Restangular = _Restangular_;
  10.         httpBackend = _$httpBackend_;
  11.         scope = $rootScope.$new();
  12.         q = _$q_;
  13.  
  14.         createController = function () {
  15.             $controller('MyCtrl', {
  16.                 $scope: scope
  17.             });
  18.         };
  19.     });
  20.  
  21.     afterEach(function () {
  22.         httpBackend.verifyNoOutstandingExpectation();
  23.         httpBackend.verifyNoOutstandingRequest();
  24.     });
  25.  
  26.     it('should edit a node', function() {
  27.         createController();
  28.         spyOn(Restangular, 'one').and.callThrough();
  29.         scope['lists'][level].push(newFakeNode);
  30.         expect(scope['lists'][level].length).toBe(1); // this expectation fulfilled when running test
  31.         scope.editNode(7, 'bar');
  32.         httpBackend.expectPUT('/nodes/7', JSON.stringify({name : 'foo'})).respond(200);
  33.         httpBackend.flush();
  34.         scope.$apply();
  35.         expect(Restangular.one).toHaveBeenCalledWith('/nodes', 7);
  36.         expect(scope['lists'][level].length).toBe(1); // expected 0 to be 1 since scope['lists'] equals [[], [], []] --> why?!
  37.         expect(scope['lists'][level][0].name).toBe('foo');
  38.   });
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement