2016-03-14 16 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'这样的端点。 –

相关问题