Mocha / Chai expect.to.throw not catching thrown errors

前端 未结 7 1841
傲寒
傲寒 2020-11-22 07:20

I\'m having issues getting Chai\'s expect.to.throw to work in a test for my node.js app. The test keeps failing on the thrown error, but If I wrap the test case

7条回答
  •  既然无缘
    2020-11-22 08:09

    One other possible implementation, more cumbersome than the .bind() solution, but one that helps to make the point that expect() requires a function that provides a this context to the covered function, you can use a call(), e.g.,

    expect(function() {model.get.call(model, 'z');}).to.throw('...');

提交回复
热议问题