1

我有一个非常基本的 Ember-CLI 应用程序,运行着大约 75 个左右的 QUnit 断言,这些断言都通过了。当我生成验收测试时:

ember generate acceptance-test games

产生:

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';

var application;

module('Acceptance: Games', {
  beforeEach: function() {
    application = startApp();
  },

  afterEach: function() {
    Ember.run(application, 'destroy');
  }
});

test('visiting /games', function(assert) {
  visit('/games');

  andThen(function() {
    assert.equal(currentPath(), 'games');
  });
});

然后我的测试开始在路由的 JSHint 单元测试中中断:

52. JSHint - unit/routes/games: global failure (1, 0, 1)
1. Uncaught Error: Assertion Failed: calling set on destroyed object
Source: http://localhost:4200/assets/vendor.js:14407

我刚刚开始使用这些 Ember-CLI 集成测试,所以也许我缺少一些东西?错误似乎是我正在设置一些东西但没有在其他地方正确拆除它?即使是这种情况,我也不确定为什么添加一个验收测试会产生这种情况,而没有测试一切都通过了。

控制台还显示:

WARNING: Library "App" is already registered with Ember.
ember.debug.js:3940 Uncaught Error: Assertion Failed: calling set on destroyed object

作为参考,我在:

DEBUG: Ember      : 1.10.0
DEBUG: Ember Data : 1.0.0-beta.15
DEBUG: jQuery     : 1.11.2

提前致谢,

更新:

从验收测试中删除生成的代码并替换为以下内容时:

assert.ok(true);

所有的测试都通过了。只要我添加如下内容:

visit('/games');

然后,我开始在各种单元测试中随机看到“对已破坏对象的调用集”错误。

4

1 回答 1

1

我终于找到了这个。问题在于一个初始化程序,它本质上创建了一个运行时钟(类似这样),我用它来随着时间的推移重绘视图。

我的初始化程序正在使用setTimeout它更新初始化程序的属性。鉴于错误消息,我假设初始化程序的寿命比给定测试长,并且setProperties在被销毁后调用。

目前,我用以下方式包裹了我的计时器:

if (!this.get('isDestroyed') && !this.get('isDestroying')) {
...
}

只是为了让测试通过,但似乎我应该setTimeout一起摆脱所有的支持Ember.run.later

于 2015-03-02T12:48:37.330 回答