Reputation: 667
I've created an Ember test helper, which works correctly and is used successfully in an Ember qunit test, however every time JSHint runs it always gives me an error saying my test helper is not defined.
Is there something else I need to do to register my test helper? If not, is there a way I can suppress this error in JSHint?
Here is my Ember test helper. It gives no run-time errors, my tests pass successfully, and I've even set a break point and stepped through it with the debugger so I know the JSHint error is a false positive.
Ember.Test.registerHelper('hasText', function (app, selector, text) {
...
});
This is defined in a custom.js helper file, which is being imported in the /tests/test-helper.js file that was generated for me by Ember-cli.
import resolver from './helpers/resolver';
import { setResolver } from 'ember-qunit';
import testing from './helpers/custom';
setResolver(resolver);
document.write('<div id="ember-testing-container"><div id="ember-testing"></div></div>');
The errors I'm getting are:
.../tests/acceptance/outages-test.js: line 20, col 11, 'hasText' is not defined.
.../tests/acceptance/outages-test.js: line 22, col 10, 'hasText' is not defined.
Here is the acceptance test file (lines 20 and 22 are the two 'ok' lines near the bottom):
import Ember from 'ember';
import startApp from '../helpers/start-app';
var App;
module('Acceptance: Outages', {
setup: function() {
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
test('...', function() {
visit('/');
andThen(function() {
if (route('index').get('controller.outages.content').length > 0) {
ok(!hasText('.warning', 'No outages planned'), 'we have outages');
} else {
ok(hasText('.warning', 'No outages planned'), 'we have no outages');
}
});
});
I'm not sure what else I can do; I don't want these errors to keep polluting my JSHint output.
Edited to include errors and test they're occurring in.
Upvotes: 0
Views: 1403
Reputation: 667
I was able to get this working.
To register the helper functions registered with Ember.Test I needed to tell JSHint about them as well. To do this I added the helper functions to the 'predef' array located in the .jshintrc file found at the /tests root folder.
{
"predef" : [
"hasText",
...
]
}
Note that JSHint will start looking for this file in the same directory as the file that's being linted. If not found, it will move one level up the directory tree all the way up to the filesystem root so if there are any .jshintrc files in any intermediate folders those will be used instead.
Thanks to @torazaburo for pointing me in the right direction to get this working properly.
Upvotes: 3
Reputation:
JSHint has no way to know that hasText
is defined and in the global namespace courtesy of Ember.Test.registerHelper
. Best you can do is a /* global hasText */
or equivalent such as adding it to your .jshintrc
.
Upvotes: 2