ember-simple-auth: Cannot read property 'on' of undefined
I have installed the jjabrams ESA and wanted to get that in place before actually wiring it up to my OAuth based backend. With the use of the demo-app it wasn’t too hard but I am getting two extraneous errors in my unit tests that appear to map back to ESA, they’re both similar code blocks:
application-route-mixin.js
_mapSessionEventsToActions: Ember.on('init', function() {
Ember.A([
['authenticationSucceeded', 'sessionAuthenticated'],
['invalidationSucceeded', 'sessionInvalidated']
]).forEach(([event, method]) => {
this.get('session').on(event, Ember.run.bind(this, () => {
this[method](...arguments);
}));
});
}),
addon/services/session.js
_forwardSessionEvents: on('init', function() {
Ember.A([
'authenticationSucceeded',
'invalidationSucceeded'
]).forEach((event) => {
this.get('session').on(event, () => {
this.trigger(event, ...arguments);
});
});
}),
In both cases, the this.get('session') seems to resolve to an undefined object. In a project with 200 or so unit tests I only get one failure for each. The first one comes from the route/application.js where I’ve mixed in the ApplicationRouteMixin just like your demo-app. The other one is a bit more bizarre considering the error comes from a “it renders” test of a Component which does not inject the session service.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 28 (18 by maintainers)
Ah sorry, right. This isn’t actually about the test helpers. You probably needs
needs: ['service:session', 'session-store:local-storage']or whatever store you have configured.@bttf: add
needs ['service:session']to the test. As stated above, the test helpers are really for integration tests not unit tests.