Skip to content

Commit

Permalink
(FatalBadgers#1) Fixed unit test, which tests successful post request…
Browse files Browse the repository at this point in the history
… to /api/users/me/search
  • Loading branch information
scottrice10 committed Feb 4, 2015
1 parent 19701f7 commit bbc09a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
1 change: 0 additions & 1 deletion client/app/search/search.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ angular.module('tikrApp')

// returns a promise
$scope.fetchUsers = function() {

User.search({
skill: $scope.skill
}, function(data) {
Expand Down
36 changes: 20 additions & 16 deletions client/app/search/search.controller.spec.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
'use strict';

describe('Controller: SearchCtrl', function () {
describe('Controller: SearchCtrl', function() {

// load the controller's module
beforeEach(module('tikrApp'));

var SearchCtrl,
scope,
$httpBackend;
var SearchCtrl, $scope, createController, httpBackend;

// Initialize the controller and a mock scope
beforeEach(inject(function (_$httpBackend_, $controller, $rootScope) {
$httpBackend = _$httpBackend_;
$httpBackend.expectPOST('/api/users/me/search')
.respond([{'name': 'joe'}, {'name':'jim'}]);
scope = $rootScope.$new();
SearchCtrl = $controller('SearchCtrl', {
$scope: scope
});
beforeEach(inject(function($controller, $rootScope, $httpBackend) {
httpBackend = $httpBackend;
$scope = $rootScope.$new();
createController = function() {
SearchCtrl = $controller('SearchCtrl', {
$scope: $scope
});
}
}));

it('should be able to fetch all users', function () {
scope.fetchUsers()
.then(function(users){
expect(users.length).toBe(2);
it('should be able to fetch all users by language = javascript', function() {
createController();
var searchInput = null;

httpBackend.whenPOST('/api/users/me/search').respond(function(method, url, data, headers){
searchInput = JSON.parse(data).skill;
return [302, {}, {}];
});
httpBackend.flush();

expect(searchInput).toBe('javascript');
});
});

0 comments on commit bbc09a5

Please sign in to comment.