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

Need to inject config:environment into all unit tests that touch Apollo #55

Closed
bgentry opened this issue Sep 27, 2017 · 1 comment
Closed

Comments

@bgentry
Copy link
Member

bgentry commented Sep 27, 2017

Follow-up from #53.

It's a bit annoying to have to use a needs: ['config:environment'] in addition to already needing a service:apollo in any unit test that touches Apollo. As of now, this blows up on the config.apollo call when not using that injection because config is undefined here.

One way I'm working around this in my own tests is with this hack:

// used in environments without injected `config:environment` (i.e. unit tests):
const defaultOptions = {
  apiURL: "http://testserver.example/v1/graph",
};

export default ApolloService.extend({
  options: computed(function() {
    let config = getOwner(this).resolveRegistration("config:environment");
    if (config && config.apollo) {
      return config.apollo;
    } else if (testing) {
      return defaultOptions;
    }
    throw new Error("no Apollo service options defined");
  }),
  // ...
});

I'm not sure if there's a better way to handle this. At the very least, I think there should be a descriptive error like this when a required config isn't set up or available.

@dfreeman
Copy link
Contributor

One alternative would be to instruct folks to use integration: true rather than needs: [...] in their apollo-related unit tests, but that may feel kind of weird until it becomes the documented norm and integration goes away.

Either way, falling back to default options in tests seems like an ergonomic win 👍

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