Unit testing Angular views using translateStaticFilesLoader
See original GitHub issueDear all,
I would like to unit test my view which contains translate
filters.
The following loads the view and displays the key of my translation, but not its actual real value.
it('should load the view', inject(function($rootScope, _$templateCache_, _$compile_, $translate, $translateStaticFilesLoader, $httpBackend, $translationCache) {
$httpBackend.when('GET', 'locale-fr.json').respond({
"vehicule": "Véhicule"
});
$httpBackend.when('GET', 'locale-de.json').respond({
"vehicule": "Fahrzeug"
});
$httpBackend.expectGET('locale-fr.json');
$translateStaticFilesLoader({
key: 'fr',
prefix: 'locale-',
suffix: '.json'
});
$httpBackend.flush();
var tpl = _$templateCache_.get("/detail.tpl.html");
var scope = $rootScope.$new();
var view = _$compile_(angular.element(tpl))(scope);
scope.$digest();
console.log(view.find('th'));
}));
My view contains:
<th>{{ 'vehicule' | translate }}</th>
The expected ouput of the console should be Véhicule
but it is vehicule
.
Would you have any idea on how to provide my keys to the view?
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Testing - Angular
The testing documentation offers tips and techniques for unit and integration testing Angular applications through a sample application created with the ...
Read more >How do unit test with angular-translate - Stack Overflow
I concur with hugo, testing code that uses callable angular services in general (not only $translate but also $timeout and $interval) is pretty...
Read more >Angular unit testing 101 (with examples) - DEV Community
Angular automated testing. Skeleton of a test. Using the three Jasmine APIs mentioned above, a skeleton of a unit test should look like...
Read more >Unit Testing Angular Services, HTTP Calls and HTTP ...
This Angular 10 tutorial will provide you with enough knowledge on setting up a test file to unit test a service as well...
Read more >Unit testing Angular with Jest tutorial - YouTube
Learn how to unit test an Angular project in Jest in just a few simple steps.(Sorry about the font size, it was my...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sovattha Well, you can reduce the complexity of this case to the thing want to test: your template. Instead of retesting angular-translate’s async loading process, I would recommend
$httpBackend
So, using copy-paste of your code of the op:
Thank you knalli, yes in a way, you are right. I try to test too much things in the same test. I will follow your guideline. Thanks!