Search code examples
ember.jsember-cli

Ember CLI Test Helpers


Can somebody point me to a resource on how to implement a test helper with ember-cli?

Or else a simple explanation?

I know the helpers go in the test/helpers directory, but how do you load them into the integration tests?

Thanks


Solution

  • The only way I found to do this is:

    // tests/helpers/controller.js
    import Ember from 'ember';
    
    Ember.Test.registerHelper('controller', function (app, name) {
      return app.__container__.lookup('controller:' + name);
    });
    

    then in my acceptance test:

    // acceptance/index-test.js
    import Ember from 'ember';
    // import our helper (this might be done within helpers/start-app.js to always import all helpers)
    import '../helpers/controller';
    import startApp from '../helpers/start-app';
    
    // your tests using the helper(s)
    

    But there might be some better way of doing.