I have the following controller...
angular.module('jobBoard').controller('JobListController', ['$scope','$window', function($scope, $window){
$scope.keywordPlaceholder = 'What kind of job?';
$scope.locationPlaceholder = 'Where? (city, state or zip)';
$scope.onResize = function(){
if ($window.innerWidth <= 480){
$scope.keywordPlaceholder = 'What?';
$scope.locationPlaceholder = 'Where?';
}
}
angular.element($window).bind('resize', function(){
$scope.onResize();
$scope.$apply();
})
$scope.onResize();
$scope.loadJobs();
}]);
and this is the jasmine test...
describe('JobListController', function(){
var scope, controller;
describe('binding resize to window', function(){
var mockWindow = {
resize: function(){}
}
beforeEach(inject(function($rootScope, $controller){
scope = $rootScope.$new();
$controller('JobListController', { $scope:scope, $window: mockWindow});
}))
it('binds to the resize function', function(){
spyOn(scope, 'onResize');
spyOn(scope, '$apply');
mockWindow.resize();
expect(scope.onResize).toHaveBeenCalled();
expect(scope.$apply).toHaveBeenCalled();
})
})
})
but it's failing on the scope.onResize expectation. I've googled like crazy on how to properly do this but can't seem to find the right answer. Any ideas? Thanks.