 
   beforeEach module 'app.controllers.fitness'
 
-  beforeEach inject ($rootScope, $controller) ->
+  beforeEach inject ($rootScope, $controller, _$timeout_) ->
     $scope = $rootScope.$new()
+    $timeout = _$timeout_
     $controller 'fitnessCtrl',
       $scope: $scope
       Fitbit: fitbitStub

      expect($scope.activity).toEqual activityResponse

    it 'loads latest fitbit api activity time series data into the chart', ->
      expect($scope.stepChartConfig.data.json).toEqual tsActivityResponse['activities-tracker-steps']

    it 'loads latest fitbit api sleep time series data into the chart', ->
      expect($scope.sleepChartConfig.data.json).toEqual tsSleepResponse['sleep-minutesAsleep']

    it 'defaults the time series data to 1 week', ->
      expect(fitbitStub.activity_time_series_data).toHaveBeenCalledWith('1w')
      expect(fitbitStub.sleep_time_series_data).toHaveBeenCalledWith('1w')



    it 'get the data for the new time frame', ->
      $scope.setTimeFrame('1m')
      $timeout.flush()
      expect(fitbitStub.activity_time_series_data).toHaveBeenCalledWith('1m')
      expect(fitbitStub.sleep_time_series_data).toHaveBeenCalledWith('1m')

