Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Document necessary unit test changes for async loading #170

Closed
lanterndev opened this issue Sep 18, 2013 · 5 comments
Closed

Document necessary unit test changes for async loading #170

lanterndev opened this issue Sep 18, 2013 · 5 comments

Comments

@lanterndev
Copy link

When you load translations asynchronously, you have to modify your unit tests to call $httpBackend.expectGET to avoid an unexpected request error. Could you please provide an example of how to update unit tests to do this in the nicest way? Thanks for the continued great work!

@0x-r4bbit
Copy link
Member

Hey,

This is indeed a topic that should be covered in the docs! Thanks for the heads up, will update the docs accordingly but it could take a while since we have to document it in three (the fourth is in the making) languages.

I'll leave this open and close it once it landed in canary branch.

@flashjames
Copy link

This is how I do it at the moment:

// my angular-translate setup in app.js
app.config(['$translateProvider', function ($translateProvider) {
  $translateProvider.useStorage('translationStorage');

  $translateProvider.useStaticFilesLoader({
    prefix: 'translations/locale-',
    suffix: '.json'
  });
}]);

In every unit-test where I need to flush timeout's I need to add this:

// In this test we need to do flush() so therefore this whenGET() is here.
$httpBackend.whenGET(/^translations/).respond({});

@0x-r4bbit
Copy link
Member

@jenso you could also overwrite $translateProvider behaviour within your test module configuration.

@0x-r4bbit
Copy link
Member

@jenso As you can see here: #42 (comment)

@0x-r4bbit
Copy link
Member

This landed in canary. FINALLY!

0x-r4bbit pushed a commit that referenced this issue Jun 3, 2014
chapter 22 for #170. Translate in french
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants