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

Acceptance testing w/ ember-cli 1.13.8 #291

Closed
toranb opened this issue Aug 14, 2015 · 5 comments
Closed

Acceptance testing w/ ember-cli 1.13.8 #291

toranb opened this issue Aug 14, 2015 · 5 comments

Comments

@toranb
Copy link
Contributor

toranb commented Aug 14, 2015

First off - love this project and thanks for all the hours you've put in maintaining it :)

I just upgraded from ember-cli 1.13.6 to 1.13.8 and found that even though my start-app does an import like so ...

import t from "myapp/tests/helpers/t";

I started getting errors in application code that would reference it inside the assertion block (not hbs). This includes the following helper code to setup/register the service

import Ember from 'ember';

export default Ember.Test.registerHelper('t', function(window, key, context) {
    return window.__container__.lookup('service:i18n').t(key, context);
});

I assume this is enough/over kill to get hbs code working in acceptance tests but how should I import "t" if I want to use it in my qunit assertions like so?

test('we should find the name is translated for whatever reason', function(assert) {
    visit('/');
    andThen(() => {
        var model = store.find('foo', 123);
        assert.equal(model.get('name'), t("some.translation.key.here"));
    });
});

update

I ask because ember-cli now complains saying

t["default"] is not defined

...when I run the test shown above. When I "debug" the test I just see t["default"]["default"]["default"] on and on.

@toranb
Copy link
Contributor Author

toranb commented Aug 14, 2015

Also -note for anyone else watching ... if you just want to work around this you can do the import in start-app like I show above/then add "t" to your globals (test .jshintrc file).

The real question here is how to use it w/out hacking on a global in test code

@jamesarosen
Copy link
Owner

Hmm. If you want to reference translations by key in tests, you're going to have to get access to the I18nService somehow. Perhaps this library should offer exactly the test helper you suggest:

Ember.Test.registerHelper('t', function(app, key, context) {
    return app.__container__.lookup('service:i18n').t(key, context);
});

foo["default"] is not defined usually means you're importing or exporting something incorrectly. My strong guess is that the result of Ember.Test.registerHelper is undefined. In that case, I'd try changing your test helper to

import Ember from 'ember';

Ember.Test.registerHelper('t', function(app, key, context) {
    return app.__container__.lookup('service:i18n').t(key, context);
});

export default function noop() {}

@toranb
Copy link
Contributor Author

toranb commented Aug 14, 2015

Awesome! Thanks for the insight @jamesarosen

@toranb toranb closed this as completed Aug 14, 2015
@Nitijkatiyar
Copy link

Nitijkatiyar commented Jun 21, 2018

@jamesarosen
If i add following line in t helper

export default function noop() {}

then translation text

t("some.translation.key.here")

gives result as "undefined"
and if i import t from ember/test-support

import { t } from 'ember-i18n/test-support';

it gives error-

TypeError: Cannot read property 'owner' of undefined
    at t (http://localhost:4200/assets/test-support-e854ea1694e3792f2a89a88126e2a29e.js:24739:29)
    at Object.<anonymous> (http://localhost:4200/assets/tests-30c88bd89df5e06beb29dbf77dbfac4f.js:166:37)

@jamesarosen
Copy link
Owner

I believe import { t } from 'ember-i18n/test-support only works if you're using RFC-232-style tests. Are you?

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

No branches or pull requests

3 participants