【发布时间】:2015-03-26 14:12:21
【问题描述】:
我正在尝试测试具有特定角色的登录用户是否可以更改其他用户角色。我将meteor-jasmine 与 PhantomJS 一起使用(但我也尝试了针对流星茉莉的默认浏览器 Chrome 的测试)。
我正在创建一个管理员用户(管理员角色会自动分配给创建的第一个用户)和一个标准用户在我的固定装置上进行测试。然后,我在beforeEach中登录admin用户。
describe('Users with manage-user role', function() {
beforeEach(function(done) {
Meteor.loginWithPassword('mgoldsborough@gmail.com', '12345678', function(error) {
console.log('Logged in as admin');
done();
});
});
我在afterEach 中注销了管理员。
afterEach(function(done) {
Meteor.logout(function() {
console.log('Logged out');
done();
});
});
这里在测试中,我想去一个路由,给用户添加一个角色,然后检查更改是否反映在数据库中。我正在记录的newUser._id 未定义。我也试过只记录newUser,但这也是未定义的。
it('should be able to change user roles', function(done) {
Router.go('users');
Tracker.afterFlush(function() {
var newUser = Meteor.users.findOne({email: 'devon@radworks.io'});
console.log('New user id: ' + newUser._id);
$('#user-' + newUser._id + '-roles').val('manage-users');
expect(Roles.userIsInRole(newUser, 'manage-users')).toBe(true);
expect(Roles.userIsInRole(newUser, 'edit-any')).toBe(false);
done();
});
});
});
我收到此测试错误:
错误:超时 - 在 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定的超时内未调用异步回调。
此外,Chrome 还抱怨 newUser 未定义:
来自 Tracker afterFlush 函数的异常:无法读取未定义的属性“_id”
为什么我的 newUser 变量未定义?为什么我的测试超时?有没有更好的方法来测试这个功能?
【问题讨论】:
-
Meteor.users是否真的包含您期望的用户?现在解决了吗?
标签: javascript meteor jasmine