Skip to content

test: googleAnalytics set #185

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

Merged
merged 8 commits into from
Sep 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/utils/googleAnalytics/set.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as faker from 'faker';

import * as initUtils from '../../../src/utils/googleAnalytics/initialize';
import {set} from '../../../src/utils/googleAnalytics/set';

describe('googleAnalyticsHelper.set', () => {
const setUp = () => {
const name = faker.lorem.word();
const params = {foo: faker.lorem.text()};

const gtagSpy = jest.spyOn(initUtils, 'gtag').mockImplementation(() => null);
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(() => null);

return {
name,
params,
gtagSpy,
consoleInfoSpy,
};
};

test('should record a set with params', () => {
const {params, gtagSpy, consoleInfoSpy} = setUp();

set(params);

expect(gtagSpy).toHaveBeenCalledWith('set', params);
expect(consoleInfoSpy).toHaveBeenCalledTimes(1);
});

test('should record a set with fake name and params', () => {
const {name, params, gtagSpy, consoleInfoSpy} = setUp();

set(name, params);

expect(gtagSpy).toHaveBeenCalledWith('set', name, params);
expect(consoleInfoSpy).toHaveBeenCalledTimes(1);
});
});