【发布时间】:2015-09-06 22:29:41
【问题描述】:
我正在尝试使用 Jasmine 测试 Meteor 方法,但得到一个恒定的蓝点,而不是一个红色/绿色的点,并且出现以下错误:
(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:jasmine 和 velocity:html-reporter 都已安装并包含在我的软件包中。在我可以让它工作之前需要任何额外的设置吗?谢谢
【问题讨论】:
标签: javascript meteor jasmine velocity