[英]How to use custom test helper in ember.js
I generated a custom test helper with: 我生成了一个自定义测试助手:
ember generate test-helper integration-for
Here it is with its code removed: 这是删除其代码的地方:
// tests/helpers/integration-for.js
import Ember from 'ember';
export default Ember.Test.registerHelper('integrationFor', function(app, key) {
return key;
});
I can't get it to actually work in a component-test though. 我不能让它真正在组件测试中工作。 I've tried using it directly:
我试过直接使用它:
// tests/integration/pods/components/itegration-item/component-test.js
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('integration-item', 'Integration | Component | integration item', {
integration: true
});
test('it renders the google analytics integration', function(assert) {
this.set('integration', integrationFor('key_here'));
});
Which throws a ReferenceError: integrationFor is not defined
error. 哪个抛出
ReferenceError: integrationFor is not defined
错误。
And I've also tried importing it: 我也尝试导入它:
import integrationFor from '../../../helpers/integration-for';
which doesn't seem to be correct based on the documentation . 根据文档 ,这似乎是不正确的。
The docs do not have a corresponding section in the latest versions (>2.4.x), so I'm not sure if this is the correct way to handle registering test helpers or if I'm doing this incorrectly. 这些文档在最新版本(> 2.4.x)中没有相应的部分,因此我不确定这是否是注册测试助手的正确方法,或者我做错了什么。
You need to do following things, add helper to tests/.jshintc. 您需要执行以下操作,将帮助程序添加到tests / .jshintc。 Something like this.
这样的事情。
{
"predef": [
"document",
"window",
"location",
...
"shouldHaveElementWithCount",
"dblclick",
"addContact",
"integrationFor"
],
...
}
And you need to import helper file in tests/helpers/start-app.js 而且您需要在tests / helpers / start-app.js中导入帮助文件
import integrationFor from "./integration-for";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.