EmberJS + EmberCLI Unit Test Helper Function Undefined

I am trying to get the test assistant to work using the Ember CLI, but I always get it [functionName] is undefined. Here is my test helper, as in 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 in Object.module.setup (unhost / tests / accept / login-test.js: 15:16) in Object.Test.setup (http: // localhost: 4200 / assets / test-support.js: 1063: 31) at http: // localhost: 4200 / assets / test-support.js: 1168: 10 in progress (http: // localhost: 4200 / assets / test-support.js: 887: 24) at http: / /localhost: 4200 / assets / test-support.js: 476: 5

Ember CLI?

+4
2

:

, :

//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  
}

:

//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");
  });
});

:

//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
});

:

//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");
  });
});
+3

, jshint, performLogin tests/.jshintrc predef:

"predef": [
    "document",
    "window",
    "performLogin", // like this
    ...
+1

All Articles