EmberJS:对一个组件进行单元测试说,常见的助手就像点击'和'然后'未定义

时间:2015-03-17 22:37:08

标签: ember.js ember-cli

TLDR

我正在尝试对一个非常简单的组件进行单元测试。但是,似乎没有定义一些非常常见的测试助手。这是关于单元测试组件的具体内容,因为我在集成测试中使用它们没有问题。

现在直接跳到最后的问题。

详细

错误是通用的:

click is not defined
andThen is not defined

上下文的堆栈跟踪:

Died on test #4     at Object.test (http://localhost:7357/assets/test-support.js:110:11)
at http://localhost:7357/assets/skylab.js:14977:15
at mod.state (http://localhost:7357/assets/vendor.js:150:29)
at tryFinally (http://localhost:7357/assets/vendor.js:30:14)
at requireModule (http://localhost:7357/assets/vendor.js:148:5)
at Object.TestLoader.require (http://localhost:7357/assets/test-loader.js:29:9)
at Object.TestLoader.loadModules (http://localhost:7357/assets/test-loader.js:21:18): click is not defined

组件和测试非常基础。组件:

import Ember from 'ember';

export default Ember.TextField.extend({
  classNames: ['input-span']
});

测试:

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

moduleForComponent('custom-input');

test('focus on click', function(assert) {
  assert.expect(1);

  var component = this.subject();
  this.render();

  click('input')

  assert.ok(component.$('input').is(':focus'));
});

最佳猜猜

我最好的猜测是这些帮助程序在验收测试中工作,因为startApp帮助程序创建了clickandThen辅助函数。我没有设置&我的moduleForComponent电话中的拆解代码,但看起来我不应该需要它。而且我不想在这里测试整个应用程序 - 只是一个孤立的组件。

问题

  1. 是否有其他方法可以注入这些我不知道的测试助手?
  2. 我写这些测试错了吗?我是否应该在组件测试中使用click?文档是否过时了?
  3. 是否应该按照书面形式支持,这是我应该报告的框架错误吗?

1 个答案:

答案 0 :(得分:2)

接受程度助手当前依赖于正在旋转的应用程序,因此它们不可用于单元级别测试。因为那些没有应用程序。