Yannis
Yannis

Reputation: 5426

Getting “App is not defined” in teardown while testing Ember.js (ember-cli) app

I'm trying to test a simple ember-cli app (following @bcardarella Dockyard tutorial: http://reefpoints.dockyard.com/2014/05/09/building-an-ember-app-with-rails-part-3.html)

Here's my test:

import startApp from 'wallet2/tests/helpers/start-app';
module('Integration - Landing Page', {
  setup: function() {
    var App;
    return App = startApp();
  },
  teardown: function() {
    return Ember.run(App, "destroy");
  }
});

test('Should ask me to log in', function() {
  return visit('/').then(function() {
    equal(find('h1#title').text(), 'Please login');
    return equal(find('form').length, 1);
  });
});

The test works, but I get

3. Teardown failed on Should ask me to log in: App is not defined
Source:     
    at Object.module.teardown (wallet2/tests/integration/landing-page-test.js:13:26)
    at Object.Test.teardown (http://localhost:4200/assets/qunit.js:228:35)
    at http://localhost:4200/assets/qunit.js:364:10
    at process (http://localhost:4200/assets/qunit.js:1453:24)
    at http://localhost:4200/assets/qunit.js:479:5

Here's my start-app.js

var Application = require('wallet2/app')['default'];
var Router = require('wallet2/router')['default'];

export default function startApp(attrs) {
  var App;

  var attributes = Ember.merge({
    // useful Test defaults
    rootElement: '#ember-testing',
    LOG_ACTIVE_GENERATION:false,
    LOG_VIEW_LOOKUPS: false
  }, attrs); // but you can override;

  Router.reopen({
    location: 'none'
  });

  Ember.run(function(){
    App = Application.create(attributes);
    App.setupForTesting();
    App.injectTestHelpers();
  });

  App.reset(); // this shouldn't be needed, i want to be able to "start an app at a specific URL"

  return App;
}

This is driving me crazy since yesterday. Thanks for your help!

Upvotes: 3

Views: 1627

Answers (1)

Ben Colon
Ben Colon

Reputation: 66

App is defined only in setup method. Update the module part with something like this :

    import startApp from '../../helpers/start-app'; // change this due to your folder
    var App;
    module('Integration - Landing Page', {
      setup: function() {
        App = startApp();
      },
      teardown: function() {
        Ember.run(App, "destroy");
      }
    });

Upvotes: 4

Related Questions