2016-03-14 21 views
1

我在嘗試使用cli海市蜃樓作爲模擬服務器登錄頁面的驗收測試。在應用程序中訪問時,在海市蜃樓中定義的路線可以正常工作。但是,當它試圖在燼測試它返回Cli海市蜃樓路線在接受測試中不起作用

幻影:您的Ember應用程序試圖張貼'http://localhost:4200/tests?module=Acceptance |登錄',但沒有定義路由來處理這個請求。在mirage/config.js文件中定義一條匹配此路徑的路線。你忘了添加你的名字空間嗎?

驗收測試

test('visiting /login', function(assert) { 
    server.create('login', { username: '[email protected]', password: 'password' }); 
    visit('/login'); 

    fillIn('input[placeholder="Email"]', '[email protected]'); 
    fillIn('input[placeholder="Password"]', 'password'); 
    click('button.btn-primary'); 

    andThen(function() { 
    assert.equal(currentURL(), '/route'); 
    }); 
}); 

幻影/配置

import Mirage from 'ember-cli-mirage'; 
export default function() { 
this.post('/token', function(db, request) { 
    var params = formEncodedToJson(request.requestBody); 

    if(params.username === "[email protected] && params.password === "password") { 
    return { 
     "auth":"Pass$Word", 
     "token_type":"bearer" 
    }; 
    } else{ 
    var body = { errors: 'Email or password is invalid' }; 
    return new Mirage.Response(401, {}, body); 
    } 
}); 

如何糾正這個問題?請有人幫助我。

+0

你可以添加調用'/ token' api的代碼嗎? –

+0

var credentials = this.getProperties('username','password'), authenticator ='authenticator:custom'; this.get('session')。authenticate(authenticator,credentials).then(()=> { //重定向到登錄頁面 }); – Kurshith

回答

1

問題在環境配置中。爲測試定義的配置工作正常。

+0

謝謝,的確我忘了在''environment.js'的「測試」部分中定義諸如'ENV.APP.registrationEndpoint'這樣的端點。 –

相關問題