THE SITUATION:
I am testing the function that allow the user to select a language. But I am getting the following error:
TypeError: $translate.use is not a function
I have seen similar questions in SO and other forums but they are not working for me.
THE CODE:
The configuration:
app.config(function($stateProvider, $urlRouterProvider, $translateProvider) {
$translateProvider.useSanitizeValueStrategy('sanitize');
$translateProvider.translations('EN', {
"MY_ACCOUNT": "My account",
"PROJECT_LIST": "Project List",
"SETTINGS": "Settings",
});
$translateProvider.translations("IT", {
"MY_ACCOUNT": "Mio account",
"PROJECT_LIST": "Lista progetti",
"SETTINGS": "Impostazioni",
});
$translateProvider.preferredLanguage(window.localStorage['language'] || 'EN');
$translateProvider.fallbackLanguage("EN");
The function:
$scope.select_language = function(language)
{
window.localStorage['language_code'] = language.code;
$translate.use(language.code);
$rootScope.app_language = language.code;
}
The test:
describe('App tests', function() {
beforeEach(module('my_app.controllers'));
beforeEach(inject(function(_$controller_, _$rootScope_)
{
$controller = _$controller_;
$rootScope = _$rootScope_;
$scope = _$rootScope_.$new();
$translate = {};
var controller = $controller('MainCtrl', { $scope: $scope, $rootScope: $rootScope, $translate: $translate });
}));
describe('Language tests', function()
{
it('should properly load select_language function', function()
{
$scope.select_language({ name: "italiano", url: "img/italy.png", code: "IT"});
expect($rootScope.app_language).toEqual("IT");
});
});
THE QUESTION:
Why I am receiving that error?
How can I properly test $translate.use?