问题
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