使用Karma进行EmberJS测试 - 使用PhantomJS进行runloop错误,但不使用chrome

时间:2014-02-27 23:47:50

标签: testing ember.js phantomjs karma-runner

所以我已经准备好了我可爱的测试系统,但我遇到了在我的CI服务器中运行它的问题:由于某种原因,Ember Testing抱怨运行循环,但仅在运行时在PhantomJS

这是Karma输出:

Waiting for previous execution...
PhantomJS 1.9.7 (Linux) DEBUG: 'DEBUG: -------------------------------'
PhantomJS 1.9.7 (Linux) DEBUG: 'DEBUG: Ember      : 1.4.0'
PhantomJS 1.9.7 (Linux) DEBUG: 'DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba'
PhantomJS 1.9.7 (Linux) DEBUG: 'DEBUG: Handlebars : 1.0.0'
PhantomJS 1.9.7 (Linux) DEBUG: 'DEBUG: jQuery     : 1.9.1'
PhantomJS 1.9.7 (Linux) DEBUG: 'DEBUG: -------------------------------'
Chrome 33.0.1750 (Mac OS X 10.9.1) DEBUG: 'DEBUG: -------------------------------'
Chrome 33.0.1750 (Mac OS X 10.9.1) DEBUG: 'DEBUG: Ember      : 1.4.0'
Chrome 33.0.1750 (Mac OS X 10.9.1) DEBUG: 'DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba'
Chrome 33.0.1750 (Mac OS X 10.9.1) DEBUG: 'DEBUG: Handlebars : 1.0.0'
Chrome 33.0.1750 (Mac OS X 10.9.1) DEBUG: 'DEBUG: jQuery     : 1.9.1'
Chrome 33.0.1750 (Mac OS X 10.9.1) DEBUG: 'DEBUG: -------------------------------'
Chrome 33.0.1750 (Mac OS X 10.9.1) DEBUG: 'DEBUG: For more advanced debugging, install the Ember Inspector from https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi'
PhantomJS 1.9.7 (Linux) ERROR
    Error: Assertion Failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in an Ember.run
    at /apps/contentpartnerpages/ember/app/bower_components/ember/ember.js:73
Chrome 33.0.1750 (Mac OS X 10.9.1) SLOW 0.743 secs: Chats Filter tests verify adding one chat to the store
Chrome 33.0.1750 (Mac OS X 10.9.1) SLOW 0.649 secs: Chats Filter tests verify number of missed chats
Chrome 33.0.1750 (Mac OS X 10.9.1) SLOW 0.763 secs: Chats Filter tests verify the sparklines update
Chrome 33.0.1750 (Mac OS X 10.9.1) SLOW 0.657 secs: Chats Filter tests verify global filters apply to child controllers
Chrome 33.0.1750 (Mac OS X 10.9.1) SLOW 0.783 secs: Chats Filter tests verify local filters work with global filters
PhantomJS 1.9.7 (Linux): Executed 0 of 0 ERROR (0.642 secs / 0 secs)
Chrome 33.0.1750 (Mac OS X 10.9.1): Executed 6 of 6 SUCCESS (4.301 secs / 3.966 secs)

正如您所看到的,他们显然正在使用Chrome!我想不出会有什么不同,但如果有人能指出我正确的方向,那就太棒了。

1 个答案:

答案 0 :(得分:1)

奇怪的是,这只发生在Chrome上,但是,问题很可能是在你的一个测试中,你遇到了异步问题。隔离并找到导致此问题的测试,然后查看它所涉及的代码部分。然后,你需要确保在该代码中(包括触发的观察者)set,create,destroy和ajax调用都包含在ember运行循环中:

Ember.run(function(){
  // all call that results in asynchronous operations goes here
});

一旦完成,您的问题很可能就会消失!此外,确保在等待异步调用完成的异步调用之后使用“waitFor”或“andThen”函数(取决于测试框架)。如果有效,请告诉我。

来源:

http://discuss.emberjs.com/t/guide-asynchronous-side-effects-in-testing/2905