Skip to content
This repository has been archived by the owner on May 26, 2019. It is now read-only.

Add section on stubbing services #841

Merged
merged 1 commit into from
Oct 1, 2015

Conversation

toddjordan
Copy link
Contributor

PR for issue #840

I've validated the below approach is functional, just need feedback on whether these apis are sanctioned.

@locks
Copy link
Contributor

locks commented Sep 30, 2015

🎉

@benoittgt
Copy link
Contributor

Thanks @toddjordan for this PR. I read it and it's ok for me. 👍

@@ -180,3 +180,96 @@ test('should trigger external action on form submit', function(assert) {
this.$('input').click();
});
```
### Stubbing Services

In cases where components have dependencies on Ember services, its possible to stub these
Copy link
Contributor

Choose a reason for hiding this comment

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

I think "its" should be "it's" (missing apostrophe)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll just change it to "it is"

@toddjordan toddjordan force-pushed the testing-guide-stub-services branch from 0730c86 to 737caa4 Compare September 30, 2015 12:24
```

Since services default to being singletons, we can get a reference to the service within our test
and modify values on it so that we can assert on how we expect our component to react. In the next
Copy link
Contributor

Choose a reason for hiding this comment

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

This first sentence is kind of hairy :) I think you could just remove it entirely without losing any meaning, and it would make it clearer to most people.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, so just to be clear, remove the sentence starting with "Since services default...."

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, will update

@michaelrkn
Copy link
Contributor

Thanks @toddjordan! I've added a couple notes, and also asked in the testing Slack channel for someone with more expertise to review.

### Stubbing Services

In cases where components have dependencies on Ember services, it is possible to stub these
dependencies for integration tests. Stub Ember services by using the container
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll update this to "by using the registry"

@toddjordan toddjordan force-pushed the testing-guide-stub-services branch from 737caa4 to 35932d8 Compare September 30, 2015 15:12
@pixelhandler
Copy link
Contributor

@toddjordan @michaelrkn I think the section on stubbing a service is well done 👍

integration: true,

beforeEach: function () {
this.registry.register('service:location-service', locationStub);
Copy link
Member

Choose a reason for hiding this comment

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

this.registry is the private internal registry. I do not think we should recommend using it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, then what would you suggest we use to register the stub service?

Copy link
Member

Choose a reason for hiding this comment

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

The code being added in emberjs/ember-test-helpers#105:

this.register('service:location', locationStub);

@rwjblue
Copy link
Member

rwjblue commented Sep 30, 2015

Can you update the private usage of this.registry and this.container to use the techniques being added in emberjs/ember-test-helpers#105? As soon as that PR is updated (I left a tiny tweaking comment), we can land and release an updated ember-qunit version.

minor updates

incorporate grammar feedback

Update based on additional PR feedback

Update api calls based on new public function
@toddjordan toddjordan force-pushed the testing-guide-stub-services branch from 35932d8 to c095e36 Compare September 30, 2015 20:04
@toddjordan
Copy link
Contributor Author

@rwjblue updates made. Now we'll just wait for the next ember-qunit release to make sure it works ;-)

@rwjblue
Copy link
Member

rwjblue commented Sep 30, 2015

Sounds good, I'll update here once @ef4 updates that PR to fix that last comment...

@locks locks added this to the 2.2 milestone Oct 1, 2015
@toddjordan
Copy link
Contributor Author

I see ember-qunit 0.4.12 is out. Trying it out on the examples...

@toddjordan
Copy link
Contributor Author

Validated that the updated example works on ember-qunit 0.4.12. @michaelrkn @rwjblue I believe we are good to go

locks added a commit that referenced this pull request Oct 1, 2015
@locks locks merged commit 4e9a97b into emberjs:master Oct 1, 2015
@ef4
Copy link
Contributor

ef4 commented Oct 1, 2015

I added a followup in #846 that takes advantage of the new this.inject as well.

@rwjblue
Copy link
Member

rwjblue commented Oct 1, 2015

👍

@rwjblue
Copy link
Member

rwjblue commented Oct 1, 2015

Thanks for the hard work, y'all!

@locks locks modified the milestones: 2.1, 2.2 Oct 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants