rc10house commented on code in PR #453: URL: https://github.com/apache/flagon-useralejs/pull/453#discussion_r1600182957
########## 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: Sorry, I actually meant to ask you about this to see if I could get someone else to reproduce the behavior: The commented out assert line was throwing an error, complaining that the function had been called _but_ referring to the previous test where it is supposed to be called. I confirmed this by changing the log message to 'baz'. Interestingly, this test only started this behavior after adding the .catch() statement to fetch().  -- 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