Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
How to resolve angular lang json file(angular-localization module) from jasmine test case

I have angular service method which uses angular-localization locale service . I want to write jasmine test cases for method , which are failing as jasmine is not able to resolve it. May be it is not waiting till it resolve completely

//service method
$scope.getExcelName = function() {
  var name = locale.getString('export.fileName')
  return name;
}

//lang file 
'fileName': 'Status Report'

//Jasmine test case
describe('Service:MyService', function() {
  var myService
  beforeEach(module('app'))

  beforeEach(inject(function($injector) {
    myService = $injector.get('MyService');
  }))

  it('check export name', function() {
    //myService.getExcel giving '' instead of  Status Report
    expect(myService.getExcelName()).toBe('Status Report')
  })
})

How to resolve above issue ?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It seems like you are experiencing a race condition (excerpt from the documentation):

Race conditions

Always use locale.ready() passing in the filename(s) in which the token(s) exists in that context, and enclose any other relevant calls to locale.getString() within this promise's callback function block. Failure to do so may cause unexpected (empty) results due to the asynchronous nature of your entire JavaScript application.

You may use locale.getPath() to find the filename for any given token.

So the solution should be to inject the locale service and wrap the expect line inside a locale.ready() call, e.g.:

it('check export name', function(done) {
  locale.ready('export')
    .then(function() {
      expect(myService.getExcelName()).toBe('Status Report');
      done();
    })
    .catch(done.fail);
});

Probably you should also do the same in the service itself to be safe.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda