Search Posts

Category: mocha

Using plan with AngularJS + Karma + Mocha

Is there a way to assert that an error callback will be hit? Something like this: it(‘test genericArrayResponse’, function() { let self = this; this.plan(1) return Promise.resolve(myService.genericArrayResponse({zoom:’bar’})) .catch(function (err) { self.confirm() }) }); in other words, using Mocha, how can I assert that there will be a callback? Should I just do this: it(‘test genericArrayResponse’, done => { return Promise.resolve(myService.genericArrayResponse({zoom:’bar’})) .catch(function (err) { done(!err); // simple assertion that error is truthy }) }); Source: AngularJS

Why does a failed assertion trigger a promise catch?

While writing unit tests for an angular app I was experiencing unexpected results. I was able to condense the unexpected behavior into a sample test. The should.equal(true, false, ‘should then’) assertion failure in the then block seems to trigger the catch block of the promise. describe.only(‘test’, function () { var $q, $rootScope; beforeEach(function () { inject(function(_$q_, _$rootScope_) { $q = _$q_; $rootScope = _$rootScope_.$new(); }); }); var stubService = sinon.stub(service, ‘getPanel’); it(‘shall…’, function() { //1 […]