From bbc09a53b1a234349042c0e0b283466272f34128 Mon Sep 17 00:00:00 2001 From: Scott Rice Date: Tue, 3 Feb 2015 20:22:14 -0800 Subject: [PATCH] (#1) Fixed unit test, which tests successful post request to /api/users/me/search --- client/app/search/search.controller.js | 1 - client/app/search/search.controller.spec.js | 36 ++++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/client/app/search/search.controller.js b/client/app/search/search.controller.js index f7cb357..8e00e55 100644 --- a/client/app/search/search.controller.js +++ b/client/app/search/search.controller.js @@ -8,7 +8,6 @@ angular.module('tikrApp') // returns a promise $scope.fetchUsers = function() { - User.search({ skill: $scope.skill }, function(data) { diff --git a/client/app/search/search.controller.spec.js b/client/app/search/search.controller.spec.js index 4bae5c2..1efc278 100644 --- a/client/app/search/search.controller.spec.js +++ b/client/app/search/search.controller.spec.js @@ -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'); }); });