Skip to content

Instantly share code, notes, and snippets.

@matsko
Created November 8, 2013 19:59
Show Gist options
  • Save matsko/7376746 to your computer and use it in GitHub Desktop.
Save matsko/7376746 to your computer and use it in GitHub Desktop.
describe('App', function() {
beforeEach(module('myApp'));
describe('itemHistory factory', function() {
it('should have working push and list functions', inject(function(itemHistory) {
itemHistory.push({ id : 1, title:'yes' });
expect(itemHistory.list()).toEqual([{ id :1, title:'yes'}]);
itemHistory.push({ id : 2, title:'no' });
expect(itemHistory.list()).toEqual([{ id :1, title:'yes'}, { id:2, title:'no' }]);
itemHistory.push({ id : 2, title:'again' });
expect(itemHistory.list()).toEqual([{ id :1, title:'yes'}, { id:2, title:'again' }]);
}));
});
describe('ReposCtrl', function() {
it('should have a working search', inject(function($rootScope, $controller, $compile, $location) {
var scope = $rootScope.$new();
$controller('ReposCtrl',{
$scope : scope,
ghRepos : function(q) {
return {
then : function(fn) {
if(q == 'test') {
return fn([1,2,3]);
}
else {
return fn([4,5,6]);
}
}
}
}
});
scope.searchRepos('test');
expect(scope.repos).toEqual([1,2,3]);
$location.search().q = 'more';
scope.$digest();
expect(scope.repos).toEqual([4,5,6]);
}));
});
describe('StageCtrl', function() {
it('should update the loading route when the event of the page changes', inject(function($rootScope, $controller) {
var scope = $rootScope.$new();
$controller('StageCtrl',{
$scope : scope
});
scope.loadingRoute = 'nothing';
$rootScope.$broadcast('$routeChangeStart');
expect(scope.loadingRoute).toEqual(true);
$rootScope.$broadcast('$routeChangeSuccess');
expect(scope.loadingRoute).toBe(false);
}));
});
describe('itemHistory filter', function() {
it('should provide the last ten or less values', inject(function($filter) {
var historyFilter = $filter('itemHistory');
var items = [0,1,2,3,4,5,6,7,8,9,10,11,12];
expect(historyFilter(items)).toEqual([12,11,10,9,8,7,6,5,4,3]);
}));
iit('should provide the last ten or less values', function() {
var index = [];
module(function($provide) {
$provide.factory('ghRequest', function($q) {
return function(url) {
var defer = $q.defer();
index.push(defer);
return defer.promise;
}
});
});
inject(function($filter, $rootScope, $controller) {
var scope = $rootScope.$new();
$controller('RepoCtrl',{
$scope : scope,
repoData : {
owner : { login : 'angular' }
}
});
index.shift().resolve(['collab']);
$rootScope.$digest();
expect(scope.collaborators).toEqual(['collab']);
index.shift().resolve(['commits']);
$rootScope.$digest();
expect(scope.collaborators).toEqual(['commits']);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment