Accessing properties from a service in unit test


I’m trying to test a small service I have that adds navigation items to a navigation component in the route.

I tried injecting the service at the top of the unit test for the index route like so

moduleFor('route:index', 'Unit | Route | index', {
  navigationService: Ember.inject.service('navigation')

And then in the test I have this

var navItemsLength = this.get('navigationService').get('navigationMenuItems').length

But my test output says

TypeError: this.get is not a function

What is the proper way to get that info out of the service?


After banging at it for a few and doing some deeper google searches I was able to get it working like so

// tell the unit test I need the navigation service
moduleFor('route:index', 'Unit | Route | index', {
  needs: ['service:navigation']

And then I can use it

var navItemsLength = route.get('navigationService').get('navigationMenuItems').length;


Actually I spoke too soon, this isn’t actually properly testing the functionality I want to test. Still need help on this.