2014-06-24 49 views
3

我想測試一個簡單的餘燼-CLI應用程序中拆解「應用程序沒有定義」(以下@bcardarella船塢教程:http://reefpoints.dockyard.com/2014/05/09/building-an-ember-app-with-rails-part-3.html獲得在測試Ember.js(燼-CLI)的應用程序

這裏是我的測試:

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 

這裏是我的啓動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; 
} 

從昨天開始,這讓我瘋狂。謝謝你的幫助!

回答

4

應用程序僅在安裝方法中定義。 用這樣的東西更新模塊部分:

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

是的,就是這樣,應該在全局命名空間上定義應用程序!謝謝! – Yannis

相關問題