title: How can I change property value with Sinon in unit test?
body: <p>I have this code:</p>
  
  <pre><code>AlertHelper = function () {
      return {
          DisplayToastMessage: function() {
              if ($("body &gt; .modal.small").length &gt; 1) {
                  AlertHelper.CalculateAdditionalHeight();
              }
          }
      }
  }();
  </code></pre>
  
  <p>And I tried to write unit tests with QUnit and SinonJS.</p>
  
  <p>This is the unit test:</p>
  
  <pre><code>QUnit.test('DisplayToastMessage - testing function call', function (assert) {
      var sandbox = sinon.sandbox.create();
      var mock = sinon.mock(AlertHelper);
  
      sandbox.stub($("body &gt; .modal.small"), "length", 42);
  
      var expectationCalculateAdditionalHeight = mock.expects("CalculateAdditionalHeight");
      expectationCalculateAdditionalHeight.once();
  
      AlertHelper.DisplayToastMessage();
  
      mock.verify();
      assert.ok(mock.verify(), "CalculateAdditionalHeight function is called once");
  
      sandbox.restore();
      mock.restore();
  });
  </code></pre>
  
  <p>but I receive an error "Cannot read property 'length' of undefined".
  How can I test that CalculateAdditionalHeight function is called?</p>