title: Simulating going online/offline with JSDOM
body: <p>We are working on a tutorial for the basics of offline first apps, and are using JSDOM with Tape to test our code.
  In our code we update the DOM so that a text node changes from saying "online" to "offline" and vice versa by attaching an event listener to the window and listening for the "online"/"offline" events, and <code>navigator.onLine</code> to initialise the text to online/offline. Like so: </p>
  
  <pre><code>// get the online status element from the DOM
  var onlineStatusDom = document.querySelector('.online-status');
  // navigator.onLine will be true when online and false when offline. We update the text in the online status element in the dom to reflect the online status from navigator.onLine
  if (navigator.onLine) {
    onlineStatusDom.innerText = 'online';
  } else {
    onlineStatusDom.innerText = 'offline';
  }
  
  // we use the 'online' and 'offline' events to update the online/offline notification to the user
  // in IE8 the offline/online events exist on document.body rather than window, so make sure to reflect that in your code!
  window.addEventListener('offline', function(e) {
    onlineStatusDom.innerText = 'offline';
  });
  
  window.addEventListener('online', function(e) {
    onlineStatusDom.innerText = 'online';
  });
  </code></pre>
  
  <p>We want to use JSDOM to test that when offline the offline event fires and our text node updates to say "offline".</p>
  
  <p>JSDOM has a <code>window.navigator.onLine</code> property, <a href="https://github.com/tmpvar/jsdom/blob/a6acac4e9dec4f859fff22676fb4e9eaa9139787/lib/jsdom/living/navigator/Navigator.idl#L35" rel="noreferrer">but it is read only</a>, and we can't find a way to change it (always true). It seems that it has the <a href="https://github.com/tmpvar/jsdom/blob/5f3cbd66bfd40ea3a2bca60275bfbb669d63775f/lib/jsdom/living/nodes/WindowEventHandlers-impl.js#L13-L14" rel="noreferrer">online/offline events as well</a>, but I cannot see how to get them to fire. </p>
  
  <p>How can we simulate going online/offline when testing with node? </p>