Does anyone have any good advice for testing that the ember route's connectOutlets has been successful?
For example, I have the following routes:
vault: Ember.Route.extend
route: '/vault'
connectOutlets: (router, event) ->
router.get('applicationController').connectOutlet 'exercises'
index: Ember.Route.extend
route: '/'
connectOutlets: (router, event) ->
exercises = WZ.store.find(WZ.Exercise)
router.get('exercisesController').connectOutlet 'main', 'exercisesHome', exercises
How would I go about checking that this was having the desired behaviour?
I can test the currentState.path like this:
it 'should transition to vault', ->
Ember.run =>
@router.transitionTo 'vault'
expect(@router.getPath('currentState.path')).toEqual 'root.vault'
But I don't think this is a very good test.
First, you can run the test suite by entering the command ember test , or ember t , in your terminal. This will run the suite just once. Suppose, instead, you want the suite to run after every file change. You can enter ember test --server , or ember t -s .
For creating your first test, you just need to run ember generate acceptance-test <name> . In our case, ember generate acceptance-test user-can-login-via-form . Ember CLI will create a new test file under tests/acceptance/ . After a few imports, Ember CLI adds two hooks to the module definition.
Visit http://localhost:4200/tests in your browser. When the execution of the test come upon await pauseTest() , the test will be paused, allowing you to inspect the state of your application. You can now type resumeTest() in the console of your browser to continue the test execution.
In my opinion, this code does not deserve testing.
First, let's formally define a desired behavior for this code:
When the router transitions to 'vault/index' state, and everything is OK, the following happens:
You see, all the meaningful work is done by Ember. Therefore, strictly speaking, there is nothing to test, since we do not test third-party code.
In my opinion, this code has only one thing that maybe deserves testing: whether we are providing the right data to the controller. Even then, I'd test this code only after I was faced with its misbehavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With