【问题标题】:Unable to find partial in a component test在组件测试中找不到部分
【发布时间】:2014-12-10 16:24:48
【问题描述】:

我有一个组件测试失败,因为它找不到模板正在呈现的部分。具体错误是“断言失败:无法找到名称为'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”。

【问题讨论】:

  • Partial names must start with an underscore(不是破折号)。也许这是你的问题?
  • @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”。
  • 看起来可能与 ember-cli 不兼容? github.com/stefanpenner/ember-cli/issues/2097
  • 考虑到文档 (ember-cli) 中的 example,为什么不命名不带连字符或下划线的部分?
  • @PatsyIssa 成功了,谢谢!我想知道为什么他们建议在不需要时需要以连字符或下划线开头。

标签: ember.js ember-cli ember-qunit


【解决方案1】:

发现这个问题: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'));
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2021-02-22
    • 2019-10-23
    • 2017-08-03
    • 2011-12-29
    • 2017-10-19
    • 2022-12-12
    相关资源
    最近更新 更多