jeudi 30 avril 2015

Ember-cli unit test using ember-cli-simple-auth

I'm trying to write a unit test for a controller that uses simple-auth authentication in an ajax call. Assertion tests work great but the session property does not appear to be defined in the unit test module scope.

Example action in controller:

authenticate() {
  let credentials = this.getProperties('identification', 'password');
  this.get('session').authenticate('simple-auth-authenticator:token', credentials)
    .then(() => {
      this.transitionToRoute('index');
    }, (error) => {
      this.set('errorMessage', error.error);
    });
}

Example test:

it('should not authenticate', function () {
  let controller = this.subject();
  controller.send('authenticate');
  expect(controller.get('errorMessage')).to.equal("Invalid email/password combination");
});

Session is undefined error message:

TypeError: Cannot read property 'authenticate' of undefined
at authenticate (http://localhost:7357/assets/app.js:587:28)
at mixin.Mixin.create.send (http://localhost:7357/assets/vendor.js:37164:54)
at Context.<anonymous> (http://localhost:7357/assets/app.js:2002:18)
at Context.wrapper (http://localhost:7357/assets/test-support.js:1756:27)
at invoke (http://localhost:7357/assets/test-support.js:13772:21)
at Context.suite.on.context.it.context.specify.method (http://localhost:7357/assets/test-support.js:13837:13)
at Test.require.register.Runnable.run (http://localhost:7357/assets/test-support.js:7064:15)
at Runner.require.register.Runner.runTest (http://localhost:7357/assets/test-support.js:7493:10)
at http://localhost:7357/assets/test-support.js:7571:12
at next (http://localhost:7357/assets/test-support.js:7418:14)




Aucun commentaire:

Enregistrer un commentaire