您必须将一个函数传递给
expect。像这样:
expect(model.get.bind(model, 'z')).to.throw('Property does not exist in model schema.');expect(model.get.bind(model, 'z')).to.throw(new Error('Property does not exist in model schema.'));执行此操作的方式将传递给call
expect的
结果
model.get('z')。但是要测试是否抛出了某些东西,您必须将一个函数传递给expect,该函数
expect会自行调用。
bind上面使用的方法创建了一个新函数,当调用该函数时,将
model.get使用
this设置为的值
model和设置为的第一个参数进行调用
'z'。
bind可以在这里找到对它的很好的解释。



