Testing 在服务器上登录用户以进行测试

Testing 在服务器上登录用户以进行测试,testing,meteor,Testing,Meteor,我用velocity+mocha做了一些集成测试。对于某些服务器测试,用户必须登录(Meteor.userId等必须具有有效id)。如何在服务器上登录用户(那里没有登录密码)。您可以在Meteor方法中使用this.setUserId(),并在执行任何测试之前调用它 例如 //在服务器端的测试代码中 Meteor.methods({ signMeIn:function() { this.setUserId("<_id of a user>"); } }

我用velocity+mocha做了一些集成测试。对于某些服务器测试,用户必须登录(Meteor.userId等必须具有有效id)。如何在服务器上登录用户(那里没有登录密码)。

您可以在Meteor方法中使用
this.setUserId
(),并在执行任何测试之前调用它

例如

//在服务器端的测试代码中

Meteor.methods({
    signMeIn:function() {
        this.setUserId("<_id of a user>");
    }
});

您没有指定任何关于您在何处使用userId的信息,但是自从您说Meteor.userId()之后,我假设它是一个方法。您也可以在现有测试方法的前面运行这段代码(
this.setUserId
)。

我得到
错误:无法在服务器启动的方法调用中调用setUserId
Meteor.call("signMeIn");