Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matomo tracker is not a constructor #28

Open
Estroo opened this issue Oct 16, 2024 · 0 comments
Open

Matomo tracker is not a constructor #28

Estroo opened this issue Oct 16, 2024 · 0 comments
Assignees

Comments

@Estroo
Copy link

Estroo commented Oct 16, 2024

Hi, I'm trying to encapsulate Matomo in jest mocking for my unit test. Everything worked well with useMatomo but as soon as it goes to newMatomoTracker everything goes wrong.
Following the readme, here's my implementation in my app.tsx :

const instance = new MatomoTracker({
		urlBase: MATOMO_URL as string,
		siteId: MATOMO_SITE_ID  as number,
		userId: hash(id),
		disabled: !MATOMO_TRACKING_ENABLED,
		log: false,
	});

And my react-native-mock :

jest.mock('matomo-tracker-react-native', () => {
	return {
		default: jest.fn().mockImplementation(function () {
			return {
				initialize: jest.fn(),
				trackAppStart: jest.fn(),
				trackScreenView: jest.fn(),
				trackAction: jest.fn(),
				trackEvent: jest.fn(),
				trackSiteSearch: jest.fn(),
				trackLink: jest.fn(),
				trackDownload: jest.fn(),
				track: jest.fn(),
			};
		}),
		useMatomo: jest.fn().mockReturnValue({
			trackAppStart: jest.fn(),
			trackScreenView: jest.fn(),
		}),
		MatomoTracker: jest.fn().mockImplementation(function () {
			return {
				initialize: jest.fn(),
				trackAppStart: jest.fn(),
				trackScreenView: jest.fn(),
				trackAction: jest.fn(),
				trackEvent: jest.fn(),
				trackSiteSearch: jest.fn(),
				trackLink: jest.fn(),
				trackDownload: jest.fn(),
				track: jest.fn(),
			};
		}),
	};
});

I've tried both default / define MatomoTracker but I end up with the same error :
TypeError: _matomoTrackerReactNative.default is not a constructor

If you have any idea about how to fix it
Thanks

@Estroo Estroo changed the title Matomore tracker is not a constructor Matomo tracker is not a constructor Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants