How to use custom test helper in ember.js

谁说胖子不能爱 提交于 2019-12-13 05:55:09

问题


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.

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.


回答1:


You need to do following things, add helper to 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

import integrationFor from "./integration-for";


来源:https://stackoverflow.com/questions/37819247/how-to-use-custom-test-helper-in-ember-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!