ciena-blueplanet / ember-test-utils

A set of utilities to aid in testing components
MIT License
5 stars 18 forks source link

Fixes issue with initializing components with subject #127

Closed sophypal closed 5 years ago

sophypal commented 5 years ago

PATCH

I noticed that the latest testing recommendations from Ember didn't have a clear behavior for initializing component with properties. this.owner.lookup is used to fetch singletons and non-singletons and will lazily create them with blank properties. This is not how Ember components are instantiated in a real app and so we cannot use this method to test a number of components that have logic inside init that depend on required properties.

My approach uses this.owner.__container__.factoryFor('component:my-component').create(props). Please suggest better ways if any.

I've updated the documentation since it wasn't updated previously to follow the new approach to calling subject for unit testing components.

I also updated the test to follow the latest conventions like use async/await, using helpers like render from @ember/test-helpers, accessing DOM through this.element vs this.$. Removed the need for needs array in the setup-component-test helpers because the new testing framework boots up the app and loads all dependencies. Stubbing can be done by interacting with the DI container this.owner.register this.owner.inject. Naturally, I removed test related to test dependencies.

CHANGELOG