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

Issue using ember-i18n in qunit 4.2.1 and ember-cli version 2.18.2 #483

Closed
epchristi opened this issue Apr 12, 2018 · 12 comments
Closed

Issue using ember-i18n in qunit 4.2.1 and ember-cli version 2.18.2 #483

epchristi opened this issue Apr 12, 2018 · 12 comments

Comments

@epchristi
Copy link

I am possibly doing something wrong in configuring this, but I have tried to follow the documents for setting up i18n for tests. In my qunit file, I have:

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

In my test I am using t('common.testText')...
assert.equal(page.title, t('common.testText');

But.. when the test executes, function t() fails, because the "getContext" call returns undefined, thus owner is undefined. Is that an expected case that should be handled? And/Or is this a setup issue?

@jamesarosen
Copy link
Owner

@epchristi
Copy link
Author

epchristi commented Apr 12, 2018 via email

@epchristi
Copy link
Author

Yes. That is what I mentioned when I showed the import --- are there other steps missing? (I notice t is defined)

@jamesarosen
Copy link
Owner

Is that an expected case that should be handled?

Not expected.

And/Or is this a setup issue?

Possibly. It's also possible that ember-i18n's guides for using RFC232/RFC268 tests are wrong.

Perhaps you could share more of your test file.

@epchristi
Copy link
Author

epchristi commented Apr 12, 2018

On thing that is different (although I tried using module), is we are using moduleForAcceptance to setup the qunit tests. The test itself is pretty simple.

in moduleForAcceptance('Acceptance | dashboard', {
beforeEach() {
// create a mock server for mirage
// create a page
}
});

test('Networks title', async function(assert) {
await(page.visit(...page setup in the beforeEach...));
assert.equal(page.title, t('common.networksText'));
});

ember 2.18 still generates "qunit stubs" that use moduleForAcceptance. I wonder if that's part of the issue.

In my start-app.js helper I do:
let application = Application.create(attributes);
application.setupForTesting(); // tried setupApplicationTest, but that didn't work
application.injectTestHelpers();
return application;

Then in our module-for-acceptance.js helper, it's pretty boiler-plate. this.application= startApp();

@jamesarosen
Copy link
Owner

You're using an "old-style" acceptance test, not an RFC268-style test. That means you should follow this section. Specifically, you should have

// tests/helpers/start-app.js
import './ember-i18n/test-helpers';

and shouldn't have import { t } from 'ember-i18n/test-support' in your test file.

@epchristi
Copy link
Author

I am okay with you closing this, however, I still get the "assert" that owner isn't defined. I am going to back down to qunit 4.1.1 to see if using the "old" way works as you suggestion. Thank you.

@jamesarosen jamesarosen reopened this Apr 12, 2018
@jamesarosen
Copy link
Owner

I didn't expect that! Do please document your findings here. We can add them to the wiki once you figure out what's going on.

@epchristi
Copy link
Author

epchristi commented Apr 12, 2018

I should note, this all worked prior to upgrading to ember 2.18.2

I am now trying with Qunit 4.1.1 -- I can change this out if I should go to 4.2.1

In my start-app.js file, I added:
import './ember-i18n/test-helpers';

Here is what I have so far. In my "test", I am setting it up like this:

import { tHelper } from 'ember-i18n/helper';
import { getOwner } from '@ember/application';

moduleForAcceptance('Acceptance | dashboard', {
    beforeEach() {
        getOwner(this).lookup('service:i18n').set('locale', 'en');
        this.register('helper:t', tHelper);
        ...

First, eslint fails because of t being undefined. If this works, I can put a mirage ignore for those errors, not a huge deal.
Second.. the getOwner fails. This is because getOwner(this) returns undefined.

so.. I tried removing that call.
then, this.register is undefined.

So.. those steps are not working as expected.

@jamesarosen
Copy link
Owner

First, eslint fails because of t being undefined.

You can add t to tests/.eslintrc.js. It's a global test helper like visit or fillIn.

@epchristi
Copy link
Author

epchristi commented Apr 12, 2018

okay. I backed qunit down to version 4.1.1. I removed all the register stuff and simply added the import to start-apps. I added t: true to globals of .eslintrc.js and now I have it working.

Thank you for your help! (I would close this, but realize there may be an issue with 4.2.1 using the old way.)

@jamesarosen
Copy link
Owner

jamesarosen/ember-i18n has been deprecated in favor of ember-intl.

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

2 participants