jeudi 19 mai 2016

Injection of service into Ember tests

I have read and followed EmberJS Service Injection for Unit Tests (Ember QUnit) but I'm still not able to figure where the problem is.

I would like to test if my authentication is working as expected. I have written authenticator for ember-simple-auth and session is injected into route. Code itself is working without any issues.

export default Ember.Route.extend({
  authManager: Ember.inject.service('session'),
  ...
  (in actions):
    this.get('authManager').invalidate()

Now, I want to create a test which will test if my authentication is working as I expect. So I wish to use authManager directly.

moduleFor('route:index', 'Unit | Route | xyz', {
  needs: ['service:session']
});

test('2', function(assert) {
  let route = this.subject();
  let s = route.get('authManager');

When I print the content of 's', I get ''. If I change this to something else, then response is undefined as can be expected. Problem is when I want to obtain property 'isAuthenticated' or run 'invalidate()'. In these cases I got 'undefined'. What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire