forked from FatalBadgers/tikr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FatalBadgers#1) Fixed unit test, which tests successful post request…
… to /api/users/me/search
- Loading branch information
1 parent
19701f7
commit bbc09a5
Showing
2 changed files
with
20 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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'); | ||
}); | ||
}); |