title: How to call $(document).ready(function() {…}); from another file JS
body: <p>I would like to know how to call the function below without refactoring from another js file. </p>
  
  <pre><code>$(document).ready(function() {
  
    check();
  
    function check () {
      setTimeout(function(){
        location.reload(true);
      }, 10000);
    }
  
  });
  </code></pre>
  
  <p>I saw a question exist for this issue very old one but I cannot understand how to use the answer for my function.
  <a href="https://stackoverflow.com/a/1870926/7882685">StackOverflow answer from another question</a> </p>
  
  <p>I would like to see an example with my function and the proposed solution from the link.</p>
  
  <p>My example which does not work correctly:</p>
  
  <pre><code>//= require rspec_helper
  //= require background_index
  //= require sinon
  
  
  
  describe("Background Index, timeout after 10s", function() {
    // Tweak for testing
    var doc_ready = $.readyList[0]();
  
    it ("Reload the location", function(){
      clock = sinon.useFakeTimers();
  
      var check = doc_ready.check();
      var set_timeout = doc_ready.setTimeout();
      /*var stub_check = sinon.stub(check, "check");
      var stub_timeout = sinon.stub(timeout, "setTimeout");*/
  
  
      timedOut = false;
  
  
  
      setTimeout(function () {
        timedOut = true;
      }, 1000);
  
  
      timedOut.should.be.false;
      clock.tick(10010);
      timedOut.should.be.true;
  
      clock.restore();
    });
  
  });
  </code></pre>