简单的流星方法茉莉花测试不起作用
Simple Meteor Method Jasmine Test not working
我正在尝试使用 Jasmine 测试 Meteor 方法,但得到一个恒定的蓝点而不是 red/green 一个和以下错误:
(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
都已安装并包含在我的软件包中。在我让它工作之前是否需要任何额外的设置?谢谢
Meteor 方法调用将回调函数作为最后一个参数,如此处所述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)
以便检查用户是否已登录。
我正在尝试使用 Jasmine 测试 Meteor 方法,但得到一个恒定的蓝点而不是 red/green 一个和以下错误:
(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
都已安装并包含在我的软件包中。在我让它工作之前是否需要任何额外的设置?谢谢
Meteor 方法调用将回调函数作为最后一个参数,如此处所述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)
以便检查用户是否已登录。