簡體   English   中英

如何在ember.js中使用自定義測試助手

[英]How to use custom test helper in ember.js

我生成了一個自定義測試助手:

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'; 

根據文檔 ,這似乎是不正確的。

這些文檔在最新版本(> 2.4.x)中沒有相應的部分,因此我不確定這是否是注冊測試助手的正確方法,或者我做錯了什么。

您需要執行以下操作,將幫助程序添加到tests / .jshintc。 這樣的事情。

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

而且您需要在tests / helpers / start-app.js中導入幫助文件

import integrationFor from "./integration-for";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM