我正在使用Mocha在Meteor应用程序中测试一些表单。应用程序中的路由已经过身份验证,因此只有具有“管理员”角色的用户或用户才能查看这些路由。
当测试打开浏览器以查看网址并填写表单时,它会按预期重定向到登录页面。
有没有办法在进行测试之前自动登录用户,所以我不必删除路由身份验证?
这是迄今为止的测试代码
describe( 'Create a Client', function() {
it( 'should create a new client @watch', function() {
browser.url('http://localhost:3000/dashboard/clients/new')
[...]
});
});
答案 0 :(得分:1)
使用它:
function login(user) {
browser.url('http://localhost:3000')
browser.executeAsync(function(user, done) {
Meteor.loginWithPassword(user.username, user.password, done)
}, user)
}
// now you can do this:
login({
username: 'someone',
password: 'aSecret'
});
browser.url('http://localhost:3000/dashboard/clients/new')
请注意,您需要先确保用户存在,为此您可以使用灯具。
有关详细信息,请参阅此处: https://forums.meteor.com/t/solved-how-can-i-wait-for-before-hooks-to-finish-when-testing-with-chimp-meteor-cucumber/18356/12