jeudi 11 août 2016

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.




Aucun commentaire:

Enregistrer un commentaire