如何测试依赖于Meteor.user()的流星方法 [英] How to test a meteor method that relies on Meteor.user()

查看:185
本文介绍了如何测试依赖于Meteor.user()的流星方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定测试我的代码的最佳方法,并且遇到了我尝试的每个方向的复杂问题。

I am trying to determine the best way to test my code and am running into complications from every direction I've tried.

基本代码是这样的(虽然由于实际实现这一点的几层触发器,更加复杂:

The basic code is this (though far more complex due to several layers of "triggers" that actually implement this):


  1. 客户端填充对象

  2. 客户端调用流星方法并传递对象

  3. Meteor方法使用Meteor.user()获取当前用户,向对象添加createdby属性,插入对象,然后创建另一个对象(不同类型),具有依赖于第一个对象的各种属性,以及数据库中已有的一堆其他东西

我正在尝试使用Velocity和Jasmine。我更喜欢集成测试这些步骤来创建第一个对象,然后测试第二个对象是否正确创建。

I'm trying to use Velocity and Jasmine. I'd prefer to integration test these steps to create the first object and then test that the second object is properly created.

我的问题是,如果我在服务器上执行此操作,则Meteor.user()调用不起作用。如果我在客户端上执行此操作,我需要订阅大量的集合才能使逻辑工作,这看起来很糟糕。

My problem is that if I do it on the server, the Meteor.user() call doesn't work. If I do it on the client, I need to subscribe to a large number of collections in order for the logic to work, which seems kludgy.

有更好的方法吗?有没有办法在服务器集成测试中模拟或模拟用户登录?

Is there a better approach? Is there a way to simulate or mock a user login in a server integration test?

推荐答案

在你的茉莉花测试中你可以模拟一个如此调用 Meteor.user()

In your jasmine test you can mock a call to Meteor.user() like so:

spyOn(Meteor, "user").and.callFake(function() {
    return 1234; // User id
});

这篇关于如何测试依赖于Meteor.user()的流星方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆