So, I use mocha with chai to run my front tests, but I'm starting to turn on the sine and really love it. Except that the errors during the testing of the tests do not work, as shown by the synonymic documents.
Basically, I have this method:
create: function(bitString, collectionType) { var collection; switch(collectionType) { case 'minutesOfHour': collection = this.createMinutesOfHour(bitString); break; case 'hoursOfDay': collection = this.createHoursOfDay(bitString); break; case 'daysOfWeek': collection = this.createDaysOfWeek(bitString); break; case 'daysOfMonth': collection = this.createDaysOfMonth(bitString); break; case 'monthsOfYear': collection = this.createMonthsOfYear(bitString); break; default: throw new Error('unsupported collection type ' + collectionType); } return collection; },
and I am testing it with this expectation:
it('throws error if missing second arguement', function() { sinon.spy(factory, 'create'); factory.create(); expect(factory.create).to.have.thrown(); factory.create.restore(); });
however, the error I'm trying to check also seems to stop the test from running
![error message](https://fooobar.com//img/4e17d78856c942141de2a1264763fe36.png)
I would suggest that sinon.spy would include some try / catch logic inside, spy.throw would not seem just as useful without it.
http://sinonjs.org/docs/#spies
Am I doing something wrong?
noTxt source share