Created
September 28, 2013 16:18
-
-
Save zdwolfe/6743666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user.js: | |
'use strict'; | |
angular.module('myApp') | |
.controller('UserCtrl', function ($scope, Restangular) { | |
$scope.users = Restangular.all('user').getList(); | |
}); | |
user_test.js (test): | |
'use strict'; | |
describe('Controller: UserCtrl', function () { | |
beforeEach(module('myApp')); | |
var UserCtrl; | |
var scope; | |
var httpBackend; | |
// Initialize the controller and a mock scope | |
beforeEach(inject(function ($controller, $rootScope, $httpBackend) { | |
httpBackend = $httpBackend; | |
var fauxUsersList = [ 'foo' ]; | |
// Create a faux HTTP response on HTTP-GET /api/user | |
httpBackend.when('GET', '/api/user').respond(fauxUsersList); | |
scope = $rootScope.$new(); | |
$controller('UserCtrl', { $scope: scope }); | |
})); | |
afterEach(function() { | |
httpBackend.verifyNoOutstandingExpectation(); | |
httpBackend.verifyNoOutstandingRequest(); | |
}); | |
it('should attach a faux users list to scope', function () { | |
httpBackend.flush(); | |
console.log(JSON.stringify(scope.users)); | |
expect(scope.users.length).toBe(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'use strict';
angular.module('myApp', ["restangular"])
describe('Controller: UserCtrl', function () {
beforeEach(module('myApp'));
});