【问题标题】:How to use custom test helper in ember.js如何在 ember.js 中使用自定义测试助手
【发布时间】:2016-10-15 14:42:48
【问题描述】:

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

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

但我无法让它在组件测试中实际工作。我试过直接使用它:

// 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 is not defined 错误。

我也尝试过导入它:

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

根据documentation,这似乎不正确。

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

【问题讨论】:

    标签: javascript ember.js ember-cli ember-testing


    【解决方案1】:

    您需要做以下事情,将助手添加到tests/.jshintc。 像这样的。

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

    你需要在 tests/helpers/start-app.js 中导入帮助文件

    import integrationFor from "./integration-for";
    

    【讨论】:

    猜你喜欢
    • 2011-01-21
    • 1970-01-01
    • 2012-03-07
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多