こんにちは、流星法のテストを書こうとしています。そこで、サーバーフォルダーにファイル accountsMethods.js を作成しました
import { Meteor } from 'meteor/meteor'
Meteor.methods({
'createUser': function (email, password) {
var userObject = {
email,
password
}
Accounts.createUser(userObject)
}
})
そして accountsMethods.tests.js
import { Meteor } from 'meteor/meteor'
import { resetDatabase } from 'meteor/xolvio:cleaner'
import { Random } from 'meteor/random'
import should from 'should'
describe('accountsMethods', function () {
beforeEach(function () {
resetDatabase()
})
it('Creates User', function () {
const createUser = Meteor.server.method_handlers['createUser']
const email = 'test@example.com'
const password = '12345'
const userId = Random.id()
createUser.apply({ userId }, [email, password])
should(Meteor.users.find({}).count()).be.exactly(1)
})
})
テストでは、次のエラーが発生しましたが、これが何であるかはわかりません。
Error: Match error: Expected object, got string
at exports.check (packages/check.js:57:15)
at packages/accounts-password/password_server.js:1033:7
at tryLoginMethod (packages/accounts-base/accounts_server.js:248:14)
at AccountsServer.Ap._loginMethod (packages/accounts-base/accounts_server.js:381:5)
at Object.createUser (packages/accounts-password/password_server.js:1026:19)
at Test.<anonymous> (server/accountsMethods.tests.js:15:16)
at run (packages/practicalmeteor:mocha-core/server.js:34:29)
at Context.wrappedFunction (packages/practicalmeteor:mocha-core/server.js:63:33)
// 11
var createUser = Meteor.server.method_handlers['createUser']; // 12
var email = 'test@example.com'; // 13
var password = '12345'; // 14
var userId = Random.id(); // 15
createUser.apply({ userId: userId }, [email, password]); // 16
should(Meteor.users.find({}).count()).be.exactly(1); // 17