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

Suggest alternatives to instance initializers #33

Open
chriskrycho opened this issue Aug 17, 2021 · 0 comments
Open

Suggest alternatives to instance initializers #33

chriskrycho opened this issue Aug 17, 2021 · 0 comments

Comments

@chriskrycho
Copy link

While instance initializers are powerful and capable of doing what you describe using them for here, they are also (in my experience) pretty serious foot-guns and can make it very difficult for someone to find where something is actually configured—especially in a sufficiently large app.

An alternative recommendation and approach might be to set up the client explicitly during app boot (e.g. in the application controller or route), and to provide a test helper which does the same, so that for component tests where you care about it, you explicitly opt in:

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { setupApolloTest } from 'glimmer-apollo';

module('Integration | Component | GraphCoolYo', function(hooks) {
  setupRenderingTest(hooks);
  setupApolloTest(hooks);

  test('renders', async function (assert) {
    await render(hbs`<GraphCoolYo @id={{123}} />`);
    // etc.
  });
});

This also makes it much clearer when reading the test that it does need this kind of thing, and isn’t just implicitly/magically working. We do this for a variety of kinds of test hooks on the app I work on and it's slightly more verbose, but way easier for people to understand.

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

No branches or pull requests

1 participant