如何在ember.js中使用自定义测试助手 [英] How to use custom test helper in ember.js

查看:77
本文介绍了如何在ember.js中使用自定义测试助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一个自定义测试助手,

I generated a custom test helper with:

ember generate test-helper integration-for

此处已删除代码:

// 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'));
});

哪个抛出 ReferenceError:integrationFor未定义错误。

我也尝试导入它:

import integrationFor from '../../../helpers/integration-for'; 

根据文档

文档在最新版本(> 2.4.x)中没有相应的部分,因此我不确定这是否是注册测试助手的正确方法,或者我做错了。

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.

推荐答案

您需要执行以下操作,将助手添加到tests / .jshintc。
这样的东西。

You need to do following things, add helper to tests/.jshintc. Something like this.

{
 "predef": [
  "document",
  "window",
  "location",
  ...
  "shouldHaveElementWithCount",
  "dblclick",
  "addContact",
  "integrationFor"
 ],
 ...
}

并且您需要在test / helpers / start-app.js

And you need to import helper file in tests/helpers/start-app.js

import integrationFor from "./integration-for";

这篇关于如何在ember.js中使用自定义测试助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆