rc10house commented on code in PR #453:
URL: https://github.com/apache/flagon-useralejs/pull/453#discussion_r1600188460


##########
test/sendLogs_spec.js:
##########
@@ -94,25 +94,24 @@ describe('sendLogs', () => {
         done();
     });
 
-    it('sends logs on page exit with navigator', () => {
-        const sendBeaconSpy = sinon.spy()
-        global.navigator = {
-            sendBeacon: sendBeaconSpy
-        };
+    it('sends logs on page exit with fetch', () => {
+        const fetchSpy = sinon.spy()
+        global.fetch = fetchSpy
+
         sendOnClose([], {on: true, url: 'test'})
         sendOnClose([{foo: 'bar'}], {on: true, url: 'test'});
         global.window.dispatchEvent(new window.CustomEvent('pagehide'))
-        sinon.assert.calledOnce(sendBeaconSpy)
+        sinon.assert.calledOnce(fetchSpy)
     });
 
     it('does not send logs on page exit when config is off', () => {
-        const sendBeaconSpy = sinon.spy()
-        global.navigator = {
-            sendBeacon: sendBeaconSpy
-        };
-        sendOnClose([{foo: 'bar'}], {on: false, url: 'test'});
-        global.window.dispatchEvent(new window.CustomEvent('pagehide'))
-        sinon.assert.notCalled(sendBeaconSpy)
+        const fetchSpy = new sinon.spy();
+        global.fetch = fetchSpy;
+
+        sendOnClose([{foo: 'baz'}], {on: false, url: 'test'});
+        global.window.dispatchEvent(new window.CustomEvent('pagehide'));
+        // sinon.assert.notCalled(fetchSpy);
+        sinon.assert.callCount(fetchSpy, 1);

Review Comment:
   In other words, once adding the .catch() call, the test failed - stating 
that the function had been called but referring to the call of the function in 
the previous test ('send logs on page exit with fetch'). I changed the test to 
ensure the function was called only 1 time. I am still not sure why this 
behavior was changing for me however, that's what I meant to ask you about.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@flagon.apache.org
For additional commands, e-mail: notifications-h...@flagon.apache.org

Reply via email to