0
我想为我的流星应用做一些单元测试(mocha/chai)。我正在使用已验证的方法(这对此应该不重要)。MeteorJS:虚拟用户及其角色做单元测试
在我的方法中,我正在检查用户是否具有管理权限来执行集合更新。
我该如何在我的单元测试中设置一个“虚拟”,因为现在测试总是会失败,出现403错误。
单元测试
describe('method',() => {
it('should update document', (done) => {
articleUpdate.call({ _id, value })
}
})
方法
const articleUpdate = new ValidatedMethod({
name: 'article.update',
validate: null,
run ({ _id, value }) {
const loggedInUser = Meteor.user()
const isAdmin = Roles.userIsInRole(loggedInUser, ['group'], 'admin')
if (!isAdmin) { throw new Meteor.Error(403, 'Access denied') }
Articles.update(_id, {
$set: { content: value }
})
}
})
我得到的错误'错误:试图包裹userIsInRole这已经是wrapped' – user3142695
好像你正试图把它包起来两次.. 。 – tomsp