编程语言
首页 > 编程语言> > javascript-在测试Ember.js(ember-cli)应用时,在拆卸中获取“未定义应用”

javascript-在测试Ember.js(ember-cli)应用时,在拆卸中获取“未定义应用”

作者:互联网

我正在尝试测试一个简单的ember-cli应用程序(在@bcardarella Dockyard教程之后:http://reefpoints.dockyard.com/2014/05/09/building-an-ember-app-with-rails-part-3.html)

这是我的测试:

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

测试有效,但是我得到了

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

这是我的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;
}

自昨天以来,这使我发疯.谢谢你的帮助!

解决方法:

应用仅在设置方法中定义.
用以下内容更新模块部分:

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

标签:ember-js,ember-cli,javascript
来源: https://codeday.me/bug/20191029/1959809.html