Search Posts

Category: chai

How to update $scope using Sinon test with $interval.flush and clock.tick

So, I have a plunker setup with the sample code in question: My problem, is that I have a function in home.controller.js PopularMovies.query(function(data) { results = data; findMovie(results[0]); console.log(“$interval Start”,; $interval(function() { ++idx; console.log(“$interval idx[” + idx + “]”,; console.log(“results[idx % results.length]”, results[idx % results.length]); findMovie(results[idx % results.length]); }, 5000); }); When triggered, expect it to call `findMovie()` every 5000ms. To test this, I have a test written in the home.controller.spec.js file: […]

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