Core: How to setup to test translate pipe in template?

Created on 15 Feb 2017  路  13Comments  路  Source: ngx-translate/core

I'm submitting a ... (check one with "x")

[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Please help!

Most helpful comment

let injector = getTestBed();
let translate = injector.get(TranslateService);
translate.use('en');

All 13 comments

Please let us know what you've tried before asking questions because at this point, the only thing I can say is, read the documentation.

This is my test spec:

This is my template:

This is the error message:

Thank you.

Hu that weird, it looks like the import and forRoot definition are correct, I don't know why you get this error :(

@ocombe I'm new to jasmine. Don't know if I miss anything.

I'm not sure why you use two beforeEach ? But other than that it seems correct

Wait, are you using version 6 or 5? The error message let me thinks that you installed version 5 but are using the configuration of version 6?

@ocombe I'm using ng2-translate 4.2.0 and angular 2.2.3. Anything wrong with it?

Nothing except that the documentation is not the same. Use this one: https://github.com/ngx-translate/core/blob/fb02ca5920aae405048ebab50e09db67d5bf12a2/README.md
And especially the import is different for the forRoot method.

Ah it works but it seems the pipe does not work correctly in the template.

@ocombe the pipe does not work in the template. Do I need to provide anything else to the testing module?

yes, you need to initiate the translate service with "use" (either in the component, or in the tests) so that it knows which lang to load

@ocombe Could you please guide me how to do it in the tests?

let injector = getTestBed();
let translate = injector.get(TranslateService);
translate.use('en');

@ocombe thank you so much I did it. Close the topic now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

louisdoe picture louisdoe  路  3Comments

egornoveo picture egornoveo  路  4Comments

gmquiroga picture gmquiroga  路  3Comments

alkemist picture alkemist  路  3Comments

apreg picture apreg  路  3Comments