jeudi 18 mai 2017

right way to test angular $timeout karma jasmine

I trying to test this part of code:

$rootScope.$on('$routeChangeSuccess', () => {
    $timeout(() => {
      vm.isLoading = false
    }, 1000);
  });

with this:

describe('end event after timeout', function () {
      beforeEach(function () {
        scope.loadingVm.isLoading = true;
        $rootScope.$broadcast('$routeChangeSuccess');
      });
      it('should check after timeout', function () {
        $timeout.flush(2001);
        $timeout.verifyNoPendingTasks();
        expect(scope.loadingVm.isLoading).toBe(false);
      });
    });

please help with the right way of testing $timeout. also I tried to use jasmine.clock(), run timeout with done(), method, but my test is fail

Aucun commentaire:

Enregistrer un commentaire