Hi guys I am trying to write a test for my meteor method. So I created a file accountsMethods.js in the server folder
import { Meteor } from 'meteor/meteor'
Meteor.methods({
'createUser': function (email, password) {
var userObject = {
email,
password
}
Accounts.createUser(userObject)
}
})
And 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)
})
})
In the tests I have the following error but I am not sure what this is about.
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
Aucun commentaire:
Enregistrer un commentaire