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

You have to pass a function to expect. Like this: 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.’)); The way you are doing it, you are passing to expect the result of calling model.get(‘z’). But to test whether something is thrown, you have to pass a … Read more

How to run a single test with Mocha?

Try using mocha’s –grep option: -g, –grep <pattern> only run tests matching <pattern> You can use any valid JavaScript regex as <pattern>. For instance, if we have test/mytest.js: it(‘logs a’, function(done) { console.log(‘a’); done(); }); it(‘logs b’, function(done) { console.log(‘b’); done(); }); Then: $ mocha -g ‘logs a’ To run a single test. Note that … Read more

tech