title: Creating a stub of document.getSelection using Sinon
body: <p>My function, which you can find below, uses <code>document.getSelection</code>to get the currently selected text on the screen. I need to be able to specify the value of <code>document.getSelection</code> so that I test my function.</p>
  
  <p>I tried creating the stub like so:</p>
  
  <pre><code>document.getSelection = sinon.stub(document, "getSelection", function() { return "Hello world!" } );
  
  var selection = wysiwyg.getCurrentRange();
  </code></pre>
  
  <p>However, It just get <code>undefined</code> for selection. Can someone tell me what I'm doing wrong?</p>
  
  <p>Here's the method I'm testing:</p>
  
  <pre><code> Wysiwyg.prototype.getCurrentRange = function() {
      var sel, range;
      if ( window.getSelection ) {
          sel = window.getSelection();
          if ( sel.getRangeAt &amp;&amp; sel.rangeCount ) {
              range = sel.getRangeAt( 0 );
          }
      } else if ( document.selection ) {
          range = document.selection.createRange();
      }
  
      return range;
   };
  </code></pre>