Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testing ember.js connectOutlet

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.

like image 900
dagda1 Avatar asked Aug 09 '12 14:08

dagda1


People also ask

How do you test ember?

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 .

How do I run ember acceptance test?

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.

How do you pause a test in Ember?

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.


Video Answer


1 Answers

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:

  1. Ember creates new instance of ExercisesHomeView
  2. Ember sets the content property of exercisesHomeController to a list of exercises
  3. Ember connects the created view to the main outlet in the ExercisesView template

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.

like image 85
tokarev Avatar answered Sep 30 '22 12:09

tokarev