Tinytest 目前还没有文档记录,但它看起来像是一个很好用的轻量级框架。我有一个依赖于一些发布/订阅数据的包,并且对如何使用它有点受阻。我似乎无法订阅用户。
我是否需要保证服务器 block 首先运行,以便可以订阅发布 block ?
我还确保我的测试包包含各种必需的 other/auth 包。
Package.on_test(function (api) {
api.use([
'accounts-ui',
'accounts-facebook', ...
我希望在 LiveData test suite 中找到一些示例甚至 Iron-Router测试套件,但还没有打开任何东西。 FWIW 我已经查看了有关使用 meteor、Laika 和 RTD 进行测试的其他链接 RTD现在看起来有点矫枉过正。
感谢指点,如何获得像下面这样的基本示例。
if Meteor.isServer
Tinytest.add "Chatbot data", (test) ->
test.equal 1, 1, "server tests running"
userdata = {
email: "c@c.com"
profile:
nickname: "chaka"
name: "chaka"
icon: "/images/bots/chaka/icon/50.png"
}
Meteor.users.insert(userdata)
check = Meteor.users.findOne()
test.isNotNull check, "can't create user"
console.log("userCheck", check) # ok
Meteor.publish 'allUsers', ->
return Meteor.users.find()
if Meteor.isClient
Tinytest.add "Chatbot create", (test) ->
Meteor.subscribe("allUsers")
user = Meteor.users.findOne()
if (user == undefined)
test.fail("cant find user:", user)
编辑:this guidance on asycn tests似乎很有关系。
最佳答案
如果你想测试你的方法是否使用正确的查找选择器订阅,我会监视 Meteor.users.find() 并检查是否使用正确的参数调用它。
var actualFind = Meteor.users.find, receivedArguments;
Meteor.users.find = function () {
receivedArguments = arguments;
actualFind.apply(actualFind, arguments);
}
然后对 receivedArguments 进行测试。
测试订阅/发布本身是 meteor 团队应该做的事情。
您应该只为您编写的代码编写单元测试。
关于javascript - 如何将 tinytest 与发布/订阅一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23337903/