【问题标题】:Error while testing Ember Components测试 Ember 组件时出错
【发布时间】:2015-09-16 08:49:38
【问题描述】:

我想测试我的 ember 组件。我没有使用 ember-cli。我遵循了 ember 指南中给出的内容。但是 this.subject() 方法是未定义的。 另外,我收到以下错误

setUp failed on <test-case-name> : assert.async is not a function
Died on test #2 : this.render is not a function
TearDown Failed on <test-case-name> : assert.async is not a function

我没有使用任何异步函数。在我的测试用例中,我只写了一行 this.render() 。

提前致谢, 库卡

【问题讨论】:

  • 2.0 指南使用 ember-cli。

标签: testing ember.js components


【解决方案1】:

默认情况下,在 Ember 2.0 中,您正在编写集成测试,而不是单元测试。并且由于某种原因,不允许您在集成测试中访问组件对象。

要使您的测试成为单元测试,请将unit: true 添加到测试模块定义中:

moduleForComponent('pretty-color', {
  unit: true,
  // specify the other units that are required for this test
  // needs: ['component:foo', 'helper:bar']
});

很遗憾,该文档目前已经过时,并且没有讨论组件集成测试。要了解有关集成测试的更多信息,请参阅http://alisdair.mcdiarmid.org/ember-component-integration-tests/

【讨论】:

  • 非常感谢 Gaurav
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-23
  • 1970-01-01
  • 2016-11-07
  • 2021-11-30
  • 2017-11-08
相关资源
最近更新 更多