How to resolve angular lang json file (angular-localization module) from jasmine test case

I have an angular service method that uses the angular localization service. I want to write jasmine test cases for a method that fails because jasmine is not capable of resolving this. Maybe he does not wait for the full resolution of the problem.

//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 solve the above problem?

+4
source share
1 answer

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

Race conditions

locale.ready(), () locale.getString() . () - JavaScript.

locale.getPath(), .

, , locale expect locale.ready(), :

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

, , .

0

Source: https://habr.com/ru/post/1673011/


All Articles