Эй, я пытаюсь выполнить модульное тестирование метода, но получаю сообщение об ошибке «Ошибка: метод createUser () не существует», когда я слежу за Accounts.createUser, однако, когда я слежу за Meteor.user, у меня нет никаких проблем , вот что у меня есть до сих пор.
сервер/методы/user.js
Meteor.methods({
'registerUser' : function (options) {
if(Meteor.user())
throw new Meteor.Error(403, "Account has already been registered, log out to create a new account");
if(options.password.length < 8)
throw new Meteor.Error(403, "Password must have at least 8 characters");
var id = Accounts.createUser(options);
if(options.type === "b") Roles.addUsersToRoles(id, 'user-b');
else Roles.addUsersToRoles(id, 'user-c');
return 0;
}
});
Accounts.validateNewUser(function (user) {
if (user.emails[0].address && user.emails[0].address.length >= 5)
return true;
throw new Meteor.Error(403, "Invalid email address");
});
Accounts.onCreateUser(function(options, user) {
if(options.type === "b"){
var key = RegKey.findOne({ key: options.key, valid: true });
if(key) RegKey.update({ _id: key._id },{ valid: false });
else throw new Meteor.Error(403, "Invalid Code");
}
return user;
});
тесты/жасмин/сервер/устройство/user.js
"use strict";
describe("User", function () {
it("should be able to register with valid email and password", function () {
spyOn(Accounts, "createUser").and.returnValue("id");
Meteor.methodMap.registerUser({
email: "[email protected]",
password: "abcd1234"
});
expect(Accounts.createUser).toHaveBeenCalledWith({
email: "[email protected]",
password: "abcd1234"
});
});
});