Skip to content

Commit c9c3186

Browse files
test: googleAnalytics set (#185)
* feat/151 setting set test * test: googleAnalytics.set 테스트 추가 * test: 변경된 set 모듈에 맞춰 변경 * fix: typing error * fix: typing error * test: using faker in params value Co-authored-by: Choi Sumin <[email protected]> * test: hide logs Co-authored-by: Choi Sumin <[email protected]>
1 parent 25d3b53 commit c9c3186

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as faker from 'faker';
2+
3+
import * as initUtils from '../../../src/utils/googleAnalytics/initialize';
4+
import {set} from '../../../src/utils/googleAnalytics/set';
5+
6+
describe('googleAnalyticsHelper.set', () => {
7+
const setUp = () => {
8+
const name = faker.lorem.word();
9+
const params = {foo: faker.lorem.text()};
10+
11+
const gtagSpy = jest.spyOn(initUtils, 'gtag').mockImplementation(() => null);
12+
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(() => null);
13+
14+
return {
15+
name,
16+
params,
17+
gtagSpy,
18+
consoleInfoSpy,
19+
};
20+
};
21+
22+
test('should record a set with params', () => {
23+
const {params, gtagSpy, consoleInfoSpy} = setUp();
24+
25+
set(params);
26+
27+
expect(gtagSpy).toHaveBeenCalledWith('set', params);
28+
expect(consoleInfoSpy).toHaveBeenCalledTimes(1);
29+
});
30+
31+
test('should record a set with fake name and params', () => {
32+
const {name, params, gtagSpy, consoleInfoSpy} = setUp();
33+
34+
set(name, params);
35+
36+
expect(gtagSpy).toHaveBeenCalledWith('set', name, params);
37+
expect(consoleInfoSpy).toHaveBeenCalledTimes(1);
38+
});
39+
});

0 commit comments

Comments
 (0)