Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use ember-i18next during integration tests #31

Closed
mhenley-uk opened this issue Jun 14, 2016 · 2 comments
Closed

Ability to use ember-i18next during integration tests #31

mhenley-uk opened this issue Jun 14, 2016 · 2 comments

Comments

@mhenley-uk
Copy link

Currently using this library as ember-i18n lacks some of the functionality we already use from i18next. Trying to write integration tests with some of our components but cannot work out how to initialise the i18n service to be utilised as part of the tests.

  1. Is this possible?
  2. If it is possible, are there any helpers that could make this easier or at the very least maybe a little but of documentation for any users of the library.

Cheers

@heathharrelson
Copy link
Member

It turns out to be possible to do this, but it's a little tricky. You can inject the i18n service into the integration test and configure it in the beforeEach() function. Because beforeEach and afterEach apparently don't respect promises (see rwjblue/ember-qunit#192) you have to use assert.async to wait for initialization to finish:

moduleForComponent('some-component', 'Integration | Component | some component', {
  integration: true,

  beforeEach(assert) {
    const done = assert.async();
    this.inject.service('i18n');
    this.get('i18n').initLibraryAsync().then(done);
  }
});

You will probably also want to adjust the i18nextOptions for the test environment to set and preload the initial language as well.

I'll document how this works before releasing the latest version later this week. I haven't looked at trying to create a test helper that initializes i18next yet, but it may be possible.

@heathharrelson
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants