Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Doc: Testing

James Alexander Rosen edited this page Jun 25, 2015 · 14 revisions

Testing

Acceptance Tests

Ember-I18n should work just fine with tests that call startApp.

Integration Tests

When testing components that rely on translated content, the recommended approach is to use an integration-style component test:

moduleForComponent("my-component", "MyComponent", {
  integration: true,

  beforeEach: function() {
    this.set('foo', 'bar');
    this.render('{{#my-component}}{{t "some.foo" foo=bar}}{{/my-component}}');
    };
  }
});

These tests don't run initializers, though, so there are two things you may have to do to get such a test working:

  1. set i18n.locale
  2. register the t helper

Unit Tests

Ember-I18n requires many things to be available in the Registry, which makes it difficult to use in unit tests. At a minimum, you would have to declare

needs: [
  'service:i18n',
  'helper:t',
  'locale:xy/translations'
]

and then set i18n.locale and register the t helper.

If you find yourself writing lots of unit tests that rely on ember-i18n and find a way to ease this pain, this project would welcome contributions!