简体   繁体   English

Meteor.js异步帮助:在服务器上设置测试数据

[英]Meteor.js Async Help: Setting Up Test Data on the Server

I'm trying to set up some test data for my environment that is using Velocity along with Cucumber and Jasmine. 我正在尝试为使用Velocity以及Cucumber和Jasmine的环境设置一些测试数据。

I'm trying to do something pretty normal - setting up some test data in the db beforehand. 我正在尝试做一些非常正常的事情-事先在数据库中设置一些测试数据。

I'm running into some issues that seem related to how async behavior works in Meteor. 我遇到了一些问题,这些问题似乎与Meteor中异步行为的工作方式有关。 I'm used to using Promises but they don't seem to be an option on this platform. 我习惯于使用Promises,但在该平台上似乎并不是一个选择。

I want to: 我想要:

  • create a user 创建一个用户
  • do a find on that user 查找该用户
  • console.log the result of that find console.log查找结果

Below is some code from my fixture file in tests/cucumber/features 下面是我的tests/cucumber/features文件tests/cucumber/features夹具文件中的一些代码

  // make a user - it correctly writes to my cucumber db
  Meteor.wrapAsync(
    Accounts.createUser({
      email: "harry@example.com",
      password: "password"
    })
  )

  // Do a find for that user
  var theUser = Meteor.wrapAsync(Meteor.users.findOne({emails: {$elemMatch: {address: "harry@example.com"}}}))

  // log out that user. The console returns `[Function]` rather than the result of the find. How do I get the result of the find?
  console.log(theUser)

Ok, figured out the answer. 好,找出答案。 Maybe this will help someone else. 也许这会帮助别人。 The find didn't need to be wrapped in Meteor.wrapAsync 发现不需要包裹在Meteor.wrapAsync

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM