Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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

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
Unit testing Meteor,调用Blaze.renderWithData不会触发onRendered钩子_Unit Testing_Meteor_Meteor Blaze - Fatal编程技术网

Unit testing Meteor,调用Blaze.renderWithData不会触发onRendered钩子

Unit testing Meteor,调用Blaze.renderWithData不会触发onRendered钩子,unit-testing,meteor,meteor-blaze,Unit Testing,Meteor,Meteor Blaze,我正在写一个meteor软件包,并正在写一些单元测试。这个包包含一些模板,所以我也想测试这些模板。模板有一个onRendered挂钩。在我的单元测试中,我调用函数Blaze.renderWithData来呈现我想要测试的模板。我希望onRendered钩子由这个函数调用。然而,事实并非如此 我用jasmine做单元测试。测试代码如下所示: for i in [0...tests.length] oneGroupTests = tests[i] describe oneGroupTest

我正在写一个meteor软件包,并正在写一些单元测试。这个包包含一些模板,所以我也想测试这些模板。模板有一个onRendered挂钩。在我的单元测试中,我调用函数Blaze.renderWithData来呈现我想要测试的模板。我希望onRendered钩子由这个函数调用。然而,事实并非如此

我用jasmine做单元测试。测试代码如下所示:

for i in [0...tests.length]
  oneGroupTests = tests[i]
  describe  oneGroupTests.name, ->
    for i in [0...oneGroupTests.tests.length]
      test = oneGroupTests.tests[i]
      do (test) ->
        it test.name, ->
          expect(test.template).toBeDefined()
          expect(test.test).toBeDefined()
          div = document.createElement("div")
          Blaze.renderWithData(Template[test.template], test.data, div)
          if test.before
            test.before($(div))
          test.test($(div))
          $(div).remove()
知道如何以编程方式调用onRendered钩子吗


谢谢

在测试您的
onRendered
例程是否启动之前,尝试调用
Tracker.flush()
。请查看此处了解更多详细信息:

出现此问题的原因可能是回调不会立即启动,而只是在下一个“计算”周期中启动


调用
Tracker.flush()。请查看此处了解更多详细信息:

出现此问题的原因可能是回调不会立即启动,而只是在下一个“计算”周期中启动


调用
Tracker.flush()
将强制Meteor重新计算所有挂起的计算。

顺便说一句,这是我们的小麻烦制造者:顺便说一句,这是我们的小麻烦制造者: