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

Unit testing components with new attrs hash #63

Closed
amk221 opened this issue Jun 15, 2015 · 5 comments
Closed

Unit testing components with new attrs hash #63

amk221 opened this issue Jun 15, 2015 · 5 comments

Comments

@amk221
Copy link
Contributor

amk221 commented Jun 15, 2015

Upgrade path to using the new attrs hash is difficult...

  1. For a unit test which calls this.render:
    The component lifecycle hooks don't get called as you would expect.
  2. For a unit test which doesn't call this.render:
    You still need to be able to get the component's attributes, but you can't, because didInitAttrs hasn't been called.
    (A potential workaround is to manually call didInitAttrs but this only works if you actually have a function called didInitAttrs)

Apologies if this is the wrong repo.

@mmahalwy
Copy link

I am experiencing this too. Any luck?

@amk221
Copy link
Contributor Author

amk221 commented Jul 16, 2015

Life is better using component integration tests, but I still think this is an issue

@mmahalwy
Copy link

Yeah, I need to switch our tests to integration tests...

@bendemboski
Copy link
Contributor

I definitely think this is worth addressing. Integration tests and unit tests are different things, and unit tests not actually simulating the running conditions of components is problematic.

Unit tests are great for white-box testing components -- trigger an action or set a property, and make sure that a computed property updated properly, or that another action was triggered or something. For the same reason that you don't always want to test your application by interacting only with the DOM (i.e. acceptance tests), you don't always want to test your components by interacting only with the DOM (i.e. integration tests). In both cases you sometimes was unit tests.

So why not just write unit tests as integration tests? Well, you can't without some serious hackery because integration tests don't give you access to the component object (this.subject() isn't implemented). But now if you write unit tests, the choice is between making sure that they don't depend on any of the lifecycle hooks or, worse yet, on the attrs hash, or you have to mock that all up yourself :(

@rwjblue
Copy link
Member

rwjblue commented Nov 30, 2017

I believe that this should work properly now with the new ember-qunit APIs. Happy to reopen if I am mistaken...

@rwjblue rwjblue closed this as completed Nov 30, 2017
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

4 participants