Note that there are some explanatory texts on larger screens.

plurals
  1. PODon't sinon.js spys catch errors?
    text
    copied!<p>So, I'm using mocha with chai to do my front-end testing, but I'm starting to incorporate sinon and really liking it. Except that testing throwing errors isn't working quite how the sinon docs seem to indicate.</p> <p>Basically, I've got this method:</p> <pre><code>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; }, </code></pre> <p>and I'm testing it with this expectation:</p> <pre><code>it('throws error if missing second arguement', function() { sinon.spy(factory, 'create'); factory.create(); expect(factory.create).to.have.thrown(); factory.create.restore(); }); </code></pre> <p>however, the error, which I'm try to test for, also seems to halt the execution of the test</p> <p><img src="https://i.stack.imgur.com/PIKo4.png" alt="error message"></p> <p>I'd thought sinon.spy would include some try / catch logic internally, spy.throw doesn't seem as useful without it.</p> <p><a href="http://sinonjs.org/docs/#spies" rel="noreferrer">http://sinonjs.org/docs/#spies</a></p> <p>Am I doing something wrong??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload