我正在尝试对一个非常简单的组件进行单元测试。但是,似乎没有定义一些非常常见的测试助手。这是关于单元测试组件的具体内容,因为我在集成测试中使用它们没有问题。
现在直接跳到最后的问题。
错误是通用的:
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
帮助程序创建了click
和andThen
辅助函数。我没有设置&我的moduleForComponent
电话中的拆解代码,但看起来我不应该需要它。而且我不想在这里测试整个应用程序 - 只是一个孤立的组件。
答案 0 :(得分:2)
接受程度助手当前依赖于正在旋转的应用程序,因此它们不可用于单元级别测试。因为那些没有应用程序。