2015-09-06 79 views
0

我想用茉莉花但得到,而不是一個紅/綠一個恆定的藍點流星方法來測試和以下錯誤:簡單流星方法茉莉測試不工作

(STDERR) connections property is deprecated. Use getConnections() method 
(STDERR) [TypeError: Cannot call method 'split' of undefined] 

我的方法是位於lib/methods.js下,我想測試的方法如下:

Meteor.methods({ 
    copy_on_write_workout: function(day) { 
     if (!Meteor.userId()) { 
      throw new Meteor.Error("not-authorized"); 
     } 
     var date = day_to_date(day, 0); 
     var workout = Workouts.findOne({ 
      day: day, 
      owner: Meteor.userId(), 
      current_week: true 
     }); 

     // not completed in the past. no need to copy it 
     if (workout.completed.length == 0 || 
      (workout.completed.length == 1 && 
      workout.completed.last().getTime() == date.getTime())) { 
       return; 
     } 

     var new_workout = workout; 
     if (workout.completed.last().getTime() == date.getTime()) { 
      new_workout.completed = [date.getTime()]; 
      Workouts.update(workout._id, {$pop: {completed: 1}}); 
     } else { 
      new_workout.completed = []; 
     } 

     Workouts.update(workout._id, {$set: {current_week: false}}); 

     delete new_workout["_id"]; 
     Workouts.insert(new_workout); 
    } 
}); 

這裏是我的簡單測試下tests/jasmine/server/unit/method.js

describe('workouts', function() { 
    it("copy_on_write_workout simple test", function() { 

     spyOn(Workouts, 'findOne'); 

     Meteor.call('copy_on_write_workout', "Monday"); 

     expect(Workouts.findOne).toHaveBeenCalled(); 

    }); 
}); 

sanjo:jasminevelocity:html-reporter都已安裝幷包含在我的軟件包中。在我可以使用這個工具之前是否需要額外的設置?謝謝

回答

1

流星方法調用採用回調函數作爲最後一個參數,如https://forums.meteor.com/t/use-meteor-call-with-jasmine-doesnt-work/6702/2所述。

我固定我的測試中通過簡單地將其更改爲:

describe('workouts', function() { 
    it("copy_on_write_workout when never completed", function() { 
     spyOn(Workouts, 'findOne'); 
     spyOn(Meteor, 'userId').and.returnValue(1); 

     Meteor.call('copy_on_write_workout', "Monday", function(err, result) { 
      expect(Workouts.findOne).toHaveBeenCalled(); 
     }); 
    }); 
}); 

此外,我添加spyOne(Meteor, 'userId').and.returnValue(1),這樣檢查,如果用戶已經登陸通行證。