Search Posts

Category: mocha

Mocha 5.1.1 is not testing all files

I upgraded mocha from ^2.2.5 to 5.1.1 in my Angular JS project. I have 11550 test cases in my application, all of which were successful before the upgrade. However, after upgrading Mocha, I’m getting irregular outputs while running grunt test such as Firefox 60.0.0 (Windows 10.0.0): Executed 6132 of 11550 (skipped 86) SUCCESS (3 mins 13.945 secs / 16.863 secs) TOTAL: 6132 SUCCESS Firefox 60.0.0 (Windows 10.0.0): Executed 868 of 11550 (skipped 9) SUCCESS (35.564 […]

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 […]