通过CLI运行时,Emberjs测试会挂起

时间:2014-11-05 19:50:59

标签: jquery ember.js ember-data phantomjs teaspoon

当我通过命令行运行时,我的Ember测试套件会超时。我已经跟踪了这一点,这是由于ajaxComplete没有触发通过调用visit而启动的AJAX请求,但同样的请求在浏览器运行时触发完整事件。

ajaxComplete事件会触发对Ember decrementAjaxPendingRequests的调用,当未调用时,它将在wait方法期间不断旋转,因为Test.pendingAjaxRequests请求不是0.您可以看到这里:

    function wait(app, value) {
      return Test.promise(function(resolve) {
        // If this is the first async promise, kick off the async test
        if (++countAsync === 1) {
          Test.adapter.asyncStart();
        }

        // Every 10ms, poll for the async thing to have finished
        var watcher = setInterval(function() {
          console.log("watcher tick");
          // 1. If the router is loading, keep polling
          var routerIsLoading = !!app.__container__.lookup('router:main').router.activeTransition;
          if (routerIsLoading) { 
            return; 
          }

          // 2. If there are pending Ajax requests, keep polling
          if (Test.pendingAjaxRequests) { 
            console.log("PENDING AJAX REQUESTS: ", Test.pendingAjaxRequests, " - RETURNING");
            return;
          }

          // 3. If there are scheduled timers or we are inside of a run loop, keep polling
          if (run.hasScheduledTimers() || run.currentRunLoop) {
            return;
         }

          if (Test.waiters && Test.waiters.any(function(waiter) {
            var context = waiter[0];
            var callback = waiter[1];
            return !callback.call(context);
          })) { 
            return;
          }
          // Stop polling
          clearInterval(watcher);


          // If this is the last async promise, end the async test
          if (--countAsync === 0) {
            Test.adapter.asyncEnd();
          }

          // Synchronously resolve the promise
          run(null, resolve, value);
        }, 10);
      });

    }

有问题的AJAX请求来自我的一条路线中的模型钩子,它是一个简单的return this.store.find('model_name')。我正在使用sinon.js伪造这个请求,如果我在查找调用上放了一个then子句,我会看到它正确返回,但它仍然没有触发它的ajaxComplete事件。 / p>

这是我的堆栈:

  • Ember:1.7.1
  • Ember-Data:1.0.0-beta.8.2a68c63a
  • Teaspoon(我的测试跑步者):0.8.0
  • jQuery:1.10.2
  • PhantomJS(CLI Test Runner):1.9.7&& 1.8.2

有人知道是否有任何未解决的问题或者堆栈的哪个特定部分可能导致它?我不知道从哪里开始。

0 个答案:

没有答案
相关问题