Reputation: 7148
I am trying to get a test helper working using Ember CLI, but I always get [functionName] is undefined
. Here is my test, helper, as according to the emberjs docs:
`import Ember from "ember"`
acceptanceHelpers = ->
Ember.Test.registerAsyncHelper("performLogin", (app) ->
visit "/login"
fillIn("#username", "sampleusername")
fillIn("#password", "samplepassword")
click(".form-actions button:first")
wait()
)
`export default acceptanceHelpers`
And where I use it: login-test.coffee
:
`import Ember from "ember"`
`import startApp from "../helpers/start-app"`
`import acceptanceHelpers from "../helpers/acceptance-helpers"`
App = null
module "Acceptance: Login",
setup: ->
App = startApp()
teardown: ->
Ember.run App, "destroy"
test "User is able to log in / transition to dashboard", ->
performLogin()
andThen ->
equal(currentRouteName(), "dashboard")
But I get:
ReferenceError: performLogin is not defined at Object.module.setup (unhost/tests/acceptance/login-test.js:15:16) at Object.Test.setup (http://
localhost
:4200/assets/test-support.js:1063:31) at http://localhost
:4200/assets/test-support.js:1168:10 at process (http://localhost
:4200/assets/test-support.js:887:24) at http://localhost
:4200/assets/test-support.js:476:5
How can I configure my acceptance test to properly use defined test helpers in Ember CLI?
Upvotes: 4
Views: 1406
Reputation: 276
A couple of options here:
You can just make a plain helper function to use, if you want to import into each test file:
//acceptance-helpers.js
export function performLogin() {
visit "/login"
fillIn("#username", "sampleusername")
fillIn("#password", "samplepassword")
click(".form-actions button:first")
// wait() <--- This wait is unnecessary, 'click' will cause a wait
}
And then in the test:
//login-test.js
import Ember from 'ember';
import startApp from '../helpers/start-app';
import { performLogin } from '../helpers/acceptance-helpers';
var App;
module("Acceptance: Login", {
setup: function(){
App = startApp();
},
teardown: function(){
Ember.run(App, 'destroy');
}
});
test("User is able to log in / transition to dashboard", function(){
performLogin();
andThen(function(){
equal(currentRouteName(), "dashboard");
});
});
Making and using a registered helper:
//Easiest is to put in test-helper.js ... it must be evaled before injectTestHelpers is called in startApp
Ember.Test.registerAsyncHelper( 'performLogin', function ( app ) {
visit "/login"
fillIn("#username", "sampleusername")
fillIn("#password", "samplepassword")
click(".form-actions button:first")
// wait() <--- wait is again unnecessary
});
And then in the test:
//login-test.js
import Ember from 'ember';
import startApp from '../helpers/start-app';
//No need to import anything to get performLogin, it was registered
var App;
module("Acceptance: Login", {
setup: function(){
App = startApp();
},
teardown: function(){
Ember.run(App, 'destroy');
}
});
test("User is able to log in / transition to dashboard", function(){
performLogin();
andThen(function(){
equal(currentRouteName(), "dashboard");
});
});
Upvotes: 3
Reputation: 4334
This is most likely jshint failing, you need to add performLogin
to tests/.jshintrc
to the predef
array:
"predef": [
"document",
"window",
"performLogin", // like this
...
Upvotes: 1