Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用速度和茉莉花测试流星时需要超时_Javascript_Meteor_Jasmine_Meteor Velocity_Meteor Jasmine - Fatal编程技术网

Javascript 使用速度和茉莉花测试流星时需要超时

Javascript 使用速度和茉莉花测试流星时需要超时,javascript,meteor,jasmine,meteor-velocity,meteor-jasmine,Javascript,Meteor,Jasmine,Meteor Velocity,Meteor Jasmine,对meteor、velocity和jasmine来说都很陌生,所以我不确定我是否做错了什么,用jasmine做了一些它不适合的事情,或者这就是它的工作方式 我发现我需要为几乎所有的测试设置超时,以便让它们通过。是这样还是我做错了什么 例如,我正在运行一些测试来检查验证消息: describe("add quote validation", function() { beforeEach(function (done) { Router.go('addQuote

对meteor、velocity和jasmine来说都很陌生,所以我不确定我是否做错了什么,用jasmine做了一些它不适合的事情,或者这就是它的工作方式

我发现我需要为几乎所有的测试设置超时,以便让它们通过。是这样还是我做错了什么

例如,我正在运行一些测试来检查验证消息:

    describe("add quote validation", function() {
      beforeEach(function (done) {
        Router.go('addQuote');
        Tracker.afterFlush(function(){
          done();
        });
      });

      beforeEach(waitForRouter);

      it("should show validation when Quote is missing", function(done) {
        $('#quote').val('');
        $('#author').val('Some author');
        Meteor.setTimeout(function(){
          $('#addQuoteBtn').click();
        }, 500);
        Meteor.setTimeout(function(){
          expect($('.parsley-custom-error-message').text()).toEqual("Quote can't be empty.");
          done();
          }, 500);
      });
    }

好的,我们遇到了完全相同的问题,并设计了一个非常优雅的解决方案,它不需要超时,是运行测试的最快方式。基本上,我们使用两种策略中的一种,这取决于您等待的屏幕元素

所有代码都会进入tests/mocha/client/lib.coffee,这不是Jasmine等价物的100%,但它应该适用于所有客户端测试代码。我把它留在了Coffeescript中,但您可以在Coffeescript.org上将它编译成Javascript,它也应该可以正常工作

如果您所做的任何操作(路由或其他类似更改反应变量的操作)导致
模板
重新渲染,则可以使用
Template..rendered
钩子来检测它何时完成渲染。因此,我们在lib.coffee中添加了以下函数:

@afterRendered = (template,f)->
    cb = template.rendered
    template.rendered = ->
      cb?()
      template.rendered = cb
      f?()
      return
    return
它有什么作用?它基本上“记住”原始的
呈现的
回调函数,并在呈现
模板
并调用原始回调函数后,用调用额外函数的回调函数临时替换它。它需要进行这种内务管理,以避免破坏任何可能依赖于
呈现的
回调的代码,因为您基本上是在直接处理Meteor代码

在测试中,您可以执行以下操作:

 it.only "should check stuff after routing", (done)->
    try
      Router.go "<somewhere>"
      afterRendered Template.<expected_template>, ->
        <your tests here>
        done()
    catch e
      done(e)
如果愿意,您可以删除控制台日志记录和辅助
it
iterator函数,它们并不重要。这允许您在测试中执行以下操作:

$('#modalId').onVisible (el)->
  <tests here>
  done()
, (el)->
  console.log "Waiting for #{el.selector}"
$(“#modalId”).onVisible(el)->
完成()
,(el)->
console.log“正在等待#{el.selector}”
如果需要,可以删除第二个函数,它是上面提到的
it
迭代器函数。但是,请注意,此特定代码使用“display:hidden”作为不可见性的标记(Bootstrap就是这样做的)。如果您的代码使用另一种机制隐藏/显示部件,请更改它


对我们来说,这是一种魅力

只是a+1,我不认为这是茉莉花特有的。我在mike:mocha软件包中看到了同样的问题,该软件包使用带有meteor和velocity的mocha。设置超时似乎是使测试可靠通过的唯一方法。我正在使用链接到的文档。如果我找到更好的方法,我会更新!谢谢你的详细回复,我把这件事搞砸了一点,它似乎工作得很好,当然比到处坚持超时更干净!好主意!这应该放在包本身中:)
$('#modalId').onVisible (el)->
  <tests here>
  done()
, (el)->
  console.log "Waiting for #{el.selector}"