title: How to test window.load() in Jasmine with a specific window.location.href?
body: <p>I have the following code:</p>
  
  <pre><code>window.onload= function() {
       var requestData = {
          bookId:$('.bookId').text()
       };
  if(window.location.href.indexOf("/viewbook")!=-1){
      $.post("check-book", requestData, function (response) {
         if(response == "already saved") {
             $('.add-btn').attr('disabled', 'disabled');
         }
      });
  }
  };
  </code></pre>
  
  <p>And I am trying to write an appropriate test in Jasmine. So, far I have the following code:</p>
  
  <pre><code>describe("should disable button", function () {
  it("should check if book exists in list while loading page", function () {
      var localContext = {
          "window":{
              location:{
                  href:"/viewbook"
              }
  
          }
      }
      with(localContext){
          spyOn($, 'post');
  
          window.load();
          expect(window.location.href).toBe("/viewbook");
          //expect($.post).toHaveBeenCalled();
      }
  });
  
  });
  </code></pre>
  
  <p>But when I run it, it gives me an error that load is not know for an Object. Do you have any idea how this can be tested?</p>
  
  <p>Thanks</p>