1

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

ajaxComplete事件触发对 Ember 的调用decrementAjaxPendingRequests,如果未调用,它将在wait方法期间不断旋转,因为Test.pendingAjaxRequestsrequests 不为 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在那个 find 调用上加上一个子句,我会看到它正确返回,但它仍然没有触发它的ajaxComplete事件。

这是我的堆栈:

  • 余烬:1.7.1
  • 灰烬数据:1.0.0-beta.8.2a68c63a
  • 茶匙(我的测试跑步者):0.8.0
  • jQuery:1.10.2
  • PhantomJS(CLI 测试运行程序):1.9.7 && 1.8.2

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

4

0 回答 0