title: Mocking Window with Sinon, Mocha, Enzyme, and React
body: <p>I'm trying to mock out the window object for a component I'm using with just the four libraries listed above.</p>
  
  <p>I know it can be done with JSDom but the client is against using it. Based on my research simply doing sinon.stub(window,'location') should work but when I run my tests I still get Window undefined in my component.</p>
  
  <p>Currently the component is called within the render return {window.location.host}</p>
  
  <p>any thoughts to what I am doing wrong to get sinon to stub out that one piece. Once I stub out that piece then I can focus on testing the other parts of that component that have nothing to do with window.</p>
  
  <p>My Test Method:</p>
  
  <pre><code>import React from 'react';
  
  import { shallow } from 'enzyme';
  import chai from 'chai';
  chai.should();
  import sinon from 'sinon';
  
  import BillingStatementRow from '../BillingStatementRow';
  
  describe('Test &lt;BillingStatementRow /&gt; Component', function() {
  
      context('Function Testing', function() {
  
          it('Test - onFieldChange - Make sure it handles NaN', function() {
  
              var e = {target: {value: NaN}};
  
              var window = { location : { host : "..." } };
  
              var mockedOnChange = sinon.spy();
  
              const wrapper = shallow (
                  &lt;BillingStatementRow slds={''} key={'1'}
                      Id={'1'} inputValue={'0'} salesInvoice={'SIN0001'}
                      invoicedAmount={1000} duedate={'1461628800000'}
                      outstandingBalance={1000} receiptRemaining={1000}
                      amountAllocated={1000} onChange={mockedOnChange.bind(this,'BS0001')} /&gt;
              );
  
              wrapper.instance().onFieldChange('amountAllocated', e);
              wrapper.update();
  
  
          })
  
  
      });
  
  });
  </code></pre>