4

我有一个组件测试失败,因为它找不到模板正在呈现的部分。具体错误是“断言失败:无法找到名称为'components/activity-list-item-content'的部分”。

我的测试文件基本上是ember-cli生成的默认文件:

import {
  moduleForComponent,
  test
} from 'ember-qunit';

moduleForComponent('activity-list-item', 'ActivityListComponent', {
  // specify the other units that are required for this test
  needs: ['helper:format-date']
});

test('it renders', function() {
  expect(2);

  // creates the component instance
  var component = this.subject();
  equal(component._state, 'preRender');

  // appends the component to the page
  this.append();
  equal(component._state, 'inDOM');
});

和看起来像这样的组件模板:

{{#if activity.momentId}}
  {{#link-to 'moment' momentId class='close-dropdown'}}
    {{partial 'components/activity-list-item-content'}}
  {{/link-to}}
{{else}}
  {{partial 'components/activity-list-item-content'}}
{{/if}}

我的应用程序运行良好,没有任何错误,所以我想知道我的测试设置中是否缺少某些东西。我也尝试将它添加到needs数组中并得到相同的错误:

needs: ['helper:format-date', 'template:components/-activity-list-item-content']

如何让我的测试找到部分?

更新

@GJK 指出部分名称应以下划线而不是破折号开头。如果我进行更改,则测试通过,但是我在控制台中收到一条弃用警告,上面写着:

弃用:模块不应包含下划线。尝试查找未找到的“myapp-ember/templates/components/-activity-list-item-content”。请将“myapp-ember/templates/components/_activity-list-item-content”重命名为“myapp-ember/templates/components/-activity-list-item-content”。

4

1 回答 1

0

发现这个问题:https ://github.com/rwjblue/ember-qunit/issues/110

当前的解决方法是:

import resolver from '../../helpers/resolver';

moduleForComponent('some-other-thing', 'component:some-other-thing', {
  needs: ['component:some-thing'],

  setup: function() {
    this.container.register('template:path/to/partial', 
           resolver.resolve('template:path/to/-partial'));
  }
});
于 2015-02-27T00:30:22.183 回答