From 85912e0f70f576cc0ac8a5ff005b02853f23c46f Mon Sep 17 00:00:00 2001 From: Timothy Stewart Date: Sat, 16 Oct 2021 17:16:19 -0500 Subject: [PATCH] chore(tests): added tests for umami and google --- src/analytics/google.test.js | 16 ++++++++++++++++ src/analytics/umami.test.js | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/analytics/google.test.js create mode 100644 src/analytics/umami.test.js diff --git a/src/analytics/google.test.js b/src/analytics/google.test.js new file mode 100644 index 0000000..a13d595 --- /dev/null +++ b/src/analytics/google.test.js @@ -0,0 +1,16 @@ +import { trackGoogleEvent } from './google'; + +it('should call gtag with event', () => { + const mockedGtag = jest.fn(); + const originalWindow = { ...window }; + const windowSpy = jest.spyOn(global, 'window', 'get'); + windowSpy.mockImplementation(() => ({ + ...originalWindow, + gtag: mockedGtag, + })); + + trackGoogleEvent('youtube-button'); + expect(mockedGtag).toBeCalledWith('event', 'youtube-button'); + + windowSpy.mockRestore(); +}); diff --git a/src/analytics/umami.test.js b/src/analytics/umami.test.js new file mode 100644 index 0000000..07ea307 --- /dev/null +++ b/src/analytics/umami.test.js @@ -0,0 +1,16 @@ +import { trackUmamiEvent } from './umami'; + +it('should call gtag with event', () => { + const mockedUmami = jest.fn(); + const originalWindow = { ...window }; + const windowSpy = jest.spyOn(global, 'window', 'get'); + windowSpy.mockImplementation(() => ({ + ...originalWindow, + umami: mockedUmami, + })); + + trackUmamiEvent('youtube-button'); + expect(mockedUmami).toBeCalledWith('youtube-button'); + + windowSpy.mockRestore(); +});