201-created / ember-cli-acceptance-test-helpers

A set of useful test helpers for ember acceptance tests.
https://www.npmjs.com/package/ember-cli-acceptance-test-helpers
MIT License
47 stars 17 forks source link

Demonstrate failure of expectComponent in ember 1.13 #23

Closed BryanCrotaz closed 9 years ago

BryanCrotaz commented 9 years ago

Upgraded addon to ember 1.13 Added component integration tests to show expectComponent doesn't work This demonstrates issue #22

BryanCrotaz commented 9 years ago

I suggest we leave this PR open until the underlying hbs renderer or Component.detectinstance are fixed

BryanCrotaz commented 9 years ago

@rwjblue is this an Ember bug, or something else?

Using the technique in http://alisdair.mcdiarmid.org/2015/06/20/ember-component-integration-tests.html render a component (possibly with components inside it). Then spin through the DOM and use Component.detectinstance to verify the component is present. Component.detectinstance returns false for the component's view.

bantic commented 9 years ago

This is unlikely to be a bug in Ember. This addon uses some quasi-private APIs to iterate through the booted app's views. The component integration tests are likely rendering in a way that is separate from the app instance, so the app's registered views do not include the stuff you have rendered.

I'll take a look at this.

BryanCrotaz commented 9 years ago

If we can work out how to make it work (and that may well require changes elsewhere), this would be a very useful feature of testing

rwjblue commented 9 years ago

@bantic - I'm happy to pair with you on this when you take a look...

bantic commented 9 years ago

@rwjblue thank you for the offer! I am hoping to take a look at it this week, and at minimum this weekend — I will give you a ping.

bantic commented 9 years ago

@BryanCrotaz I've got a version put together in a branch called expect-component-in-integration-tests that passes the tests you've added, but it doesn't work with ember-qunit version 0.4.9 (latest). It does work with version 0.4.1, though, the version you added to this PR. (The current version in this project's bower is 0.3.3, for reference — it needs to be updated).

I'm not clear on the best way to discover rendered views and am looking through the changes to ember-test-helpers to see how best to do this. For the foreseeable future the "hack" that you've done in these tests (explicitly booting an app, and passing that app to expectComponent) is going to need to be required. Official Ember Test Helpers are all designed to be used with an explicitly booted app, which isn't the recommended way of writing a component integration test helper.

BryanCrotaz commented 9 years ago

I'm not sure there is an official way to do integration tests on components yet!

BryanCrotaz commented 9 years ago

I'm seeing problems elsewhere with ember-qunit having a dependence on ember-data. ember-data appears to have a bug in beta which causes other modules to not be loaded. Is this what you're seeing perhaps?

rwjblue commented 9 years ago

I'm not sure there is an official way to do integration tests on components yet!

The ember-qunit README describes the suggested/official pattern for component integration tests.

I'm seeing problems elsewhere with ember-qunit having a dependence on ember-data

ember-qunit does not depend on ember-data at all (note no dependencies listed in rwjblue/ember-qunit-builds bower.json).

bantic commented 9 years ago

@BryanCrotaz RWJBlue gave some hints on how to fix this in a way that will work well for both acceptance and integration tests — changing it to use the container directly. I'm going to take a stab at that and this should be fixed soon.

BryanCrotaz commented 9 years ago

fantastic!

bantic commented 9 years ago

@BryanCrotaz I've released 0.4.0 which should make it possible for you to use expectComponent in integration tests. See https://github.com/201-created/ember-cli-acceptance-test-helpers/blob/master/tests/integration/expect-component-hbs-integration-test.js for how to write the tests (you do not want to use startApp, for example). Note that you'll need to be using ember-qunit version 0.4.7 or later for this to work. Let me know if you have trouble. thanks!

BryanCrotaz commented 9 years ago

That's so clean. Well played,sir!

How would you go about mocking a service now there's no app? For example I have a component that shows content if the user has the right to see it, and uses a central security service to encapsulate the "may I" question. Is it a question of resolving the service and overwriting its mayI function?
BryanCrotaz commented 9 years ago

Did you recreate my tests in your new branch, or should I submit a new PR with cleaned up tests in the correct form?

bantic commented 9 years ago

@BryanCrotaz There are here: https://github.com/201-created/ember-cli-acceptance-test-helpers/blob/master/tests/integration/expect-component-hbs-integration-test.js Are there any I missed?

BryanCrotaz commented 9 years ago

No, looks really good.