Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember Testing route redirect

I am very new to Ember and have never written a test case before. I currently have a route that is being used as a base class and will be extended by other routes to use the same behavior for redirecting. Here is what the route looks like:

import Ember from 'ember';

export default Ember.Route.extend({
  redirect: function(){
    var user = this.modelFor('application').user;
      if(Ember.isEmpty(user.get('auth'))){
        this.transitionTo('login');
      }
  },
  model: function(){
   return this.modelFor('application').user;
  }
});

So testing this manually works great, if I type in the direct url for a screen it will redirect to the login. This is the functioning code we want. I was tasked with writing unit test and have not been able to turn up anything that I found useful. This is probably my inexperience with understanding things but I need to figure out how to test this code. I would love some help and some explanation as well as to what is being done. I have to do unit tests and lots of other things for this ember project and being very new I've already wasted 2 days researching how to test this one class.

like image 856
Surep Avatar asked Oct 18 '22 04:10

Surep


1 Answers

IMO, for this route there is nothing to test with unit test. You need to write acceptance test for this route.

Look at the Ember Guides for testing routes. You don't have any property or action to write a unit test for this route. Write acceptance tests.

like image 172
ykaragol Avatar answered Oct 21 '22 00:10

ykaragol