UncleGedd edited a comment on issue #50:
URL: 
https://github.com/apache/incubator-flagon-useralejs/issues/50#issuecomment-805993603


   Ok, I've got one of the tests working:
   ```js
       it('sends logs on page exit with navigator', () => {
           const html = `<html><head></head><body></body></html>`;
           new JSDOM(html)
           const originalNavigator = global.navigator;
           let called = false;
           global.navigator = {
               sendBeacon: () => {
                   called = true;
               },
           };
   
           sendOnClose([{foo: 'bar'}], {on: true, url: 'test'});
           Object.defineProperty(global.document, 'visibilityState', {
               get: () => 'hidden'
           })
           global.document.dispatchEvent(new Event('visibilitychange'))
   
           global.navigator = originalNavigator
           expect(called).to.equal(true);
       });
   ```
   Basically I'm just faking the `visibilitychange` event and manually setting 
the `visibilityState` to "hidden" so the `sendBeacon` function will fire. 
   
   Regarding the other failing test:
   ```js
   it('sends logs on page exit without navigator', () => {
     // ...
   }
   ```
   
   In what case would we not have the `navigator`? Do we want to move away from 
using `navigator.sendBeacon` as the 
[link](https://volument.com/blog/sendbeacon-is-broken) Rob posted is suggesting?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to