Al-HUWAITI Shell
Al-huwaiti


Server : nginx/1.18.0
System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64
User : www-data ( 33)
PHP Version : 8.0.16
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/ecommerce/node_modules/pusher-js/spec/javascripts/unit/core/utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/ecommerce/node_modules/pusher-js/spec/javascripts/unit/core/utils/timers_spec.js
var timers = require('core/utils/timers');

describe("timers", function() {
  describe("Timer", function() {
    var callback;
    var timer;

    beforeEach(function() {
      jasmine.Clock.useMock();

      callback = jasmine.createSpy("callback");
      timer = new timers.OneOffTimer(123, callback);
    });

    afterEach(function() {
      timer.ensureAborted();
    });

    it("should execute the callback with the specified delay", function() {
      expect(callback).not.toHaveBeenCalled();
      jasmine.Clock.tick(122);
      expect(callback).not.toHaveBeenCalled();
      jasmine.Clock.tick(1);
      expect(callback).toHaveBeenCalled();
    });

    it("should execute the callback exactly once", function() {
      jasmine.Clock.tick(1000);
      expect(callback.calls.length).toEqual(1);
    });

    describe("#isRunning", function() {
      it("should return true before execution", function() {
        jasmine.Clock.tick(122);
        expect(timer.isRunning()).toBe(true);
      });

      it("should return false after execution", function() {
        jasmine.Clock.tick(123);
        expect(timer.isRunning()).toBe(false);
      });

      it("should return false after aborting", function() {
        timer.ensureAborted();
        expect(timer.isRunning()).toBe(false);
      });
    });

    describe("#ensureAborted", function() {
      it("should abort the timer before execution", function() {
        timer.ensureAborted();
        jasmine.Clock.tick(1000);
        expect(callback).not.toHaveBeenCalled();
      });

      it("should play nice after execution", function() {
        jasmine.Clock.tick(1000);
        timer.ensureAborted();
      });

      it("should stop callback from being called even if clearTimeout is broken", function() {
        // IE has some edge-case with clearTimeout not working, let's simulate it
        spyOn(global, "clearTimeout");
        timer.ensureAborted();
        jasmine.Clock.tick(1000);
        expect(callback).not.toHaveBeenCalled();
      });
    });
  });

  describe("PeriodicTimer", function() {
    var callback;
    var timer;

    beforeEach(function() {
      jasmine.Clock.useMock();

      callback = jasmine.createSpy("callback");
      timer = new timers.PeriodicTimer(123, callback);
    });

    afterEach(function() {
      timer.ensureAborted();
    });

    it("should execute the callback with the specified delay", function() {
      expect(callback).not.toHaveBeenCalled();
      jasmine.Clock.tick(122);
      expect(callback).not.toHaveBeenCalled();
      jasmine.Clock.tick(1);
      expect(callback).toHaveBeenCalled();
    });

    it("should execute the callback periodically", function() {
      jasmine.Clock.tick(123);
      expect(callback.calls.length).toEqual(1);
      jasmine.Clock.tick(123);
      expect(callback.calls.length).toEqual(2);
    });

    describe("#isRunning", function() {
      it("should return true before execution", function() {
        jasmine.Clock.tick(122);
        expect(timer.isRunning()).toBe(true);
      });

      it("should return true after execution", function() {
        jasmine.Clock.tick(123);
        expect(timer.isRunning()).toBe(true);
      });

      it("should return false after aborting", function() {
        timer.ensureAborted();
        expect(timer.isRunning()).toBe(false);
      });
    });

    describe("#ensureAborted", function() {
      it("should abort the timer before execution", function() {
        timer.ensureAborted();
        jasmine.Clock.tick(1000);
        expect(callback).not.toHaveBeenCalled();
      });

      it("should abort the timer after first execution", function() {
        jasmine.Clock.tick(123);
        expect(callback.calls.length).toEqual(1);
        timer.ensureAborted();
        jasmine.Clock.tick(1000);
        expect(callback.calls.length).toEqual(1);
      });

      it("should be idempotent", function() {
        timer.ensureAborted();
        timer.ensureAborted();
        jasmine.Clock.tick(1000);
        expect(callback).not.toHaveBeenCalled();
      });

      it("should stop callback from being called even if clearTimeout is broken", function() {
        // IE has some edge-case with clearTimeout not working, let's simulate it
        spyOn(global, "clearTimeout");
        timer.ensureAborted();
        jasmine.Clock.tick(1000);
        expect(callback).not.toHaveBeenCalled();
      });
    });
  });
});

Al-HUWAITI Shell