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

remove initializer, get config from environment #53

Merged
merged 1 commit into from
Sep 26, 2017

Conversation

bgentry
Copy link
Member

@bgentry bgentry commented Sep 24, 2017

Attempts to resolve #52.

Maybe @viniciussbs and @dfreeman can advise as to whether I've done this correctly, and in particular whether I should change something to avoid having to inject the config into all unit tests.

@@ -9,7 +9,7 @@ moduleFor(
'Unit | Mixin | component query manager', {
needs: ['service:apollo'],
beforeEach() {
// needed to set up config since initializers don't run here
// needed to set up config since environment won't be initialized in this type of test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add config:environment to the needs array for your unit tests, you should be able to get rid of these beforeEach blocks.

I believe the plan is for the isolated container that unit tests use to eventually go away completely, so at that point the needs will be unnecessary too.

@bgentry
Copy link
Member Author

bgentry commented Sep 25, 2017

@dfreeman d'oh, slow afternoon, thanks :)

// Need this here because apollo requires a uri, but our initializer doesn't
// run in unit tests.
// Need this here because apollo requires a uri, but our config environment
// isn't set up in unit tests.
options: {
apiURL: 'https://this-should-be-set-from-environment.example',
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dfreeman removing the beforeEach worked for the mixin unit tests, but I wasn't able to get rid of options overriding in this service test. If I remove it, these tests fail because getOwner inside the apollo service returns undefined. I must be missing something on this part...

Copy link
Contributor

@dfreeman dfreeman Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like your OverriddenService instance doesn't have an owner because you're create()-ing it manually.

Instead, you could do something like:

let customDataIdFromObject = o => o.name;
this.register('service:overridden-apollo', ApolloService.extend({
  clientOptions: // ...
}));
let service = this.container.lookup('service:overridden-apollo');
// ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean just like any other service test? 🤦‍♂️

Thanks as always!

@bgentry bgentry merged commit 2a85074 into master Sep 26, 2017
@bgentry bgentry deleted the remove-initializer branch September 26, 2017 04:19
@bgentry
Copy link
Member Author

bgentry commented Sep 27, 2017

The downside to this is that all of my unit tests of things like routes now require a needs: ['config:environment', 'service:apollo-client'] or mocks for both of these things. Not sure if there's a straightforward way around that.

@bgentry
Copy link
Member Author

bgentry commented Sep 27, 2017

Maybe the service needs to have some sort of default options set that it has to ensure that it still works in tests when config:environment isn't injected? I actually had it set up like that in my own app previously.

@bgentry
Copy link
Member Author

bgentry commented Sep 27, 2017

Opened #53 for the follow-up item.

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

Successfully merging this pull request may close these issues.

Apollo service is initializes during integration test without its options
2 participants