Skip to content

Commit 7e13306

Browse files
Update test
1 parent f1b3a1f commit 7e13306

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/trackers/__tests__/impressionsTracker.spec.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const fakeSettingsWithListener = {
3636
};
3737
const fakeWhenInit = (cb: () => void) => cb();
3838

39-
// @TODO validate logic with `impression.track` false
4039
const fakeNoneStrategy = {
4140
process: jest.fn(() => false)
4241
};
@@ -53,13 +52,6 @@ describe('Impressions Tracker', () => {
5352

5453
const strategy = strategyDebugFactory(impressionObserverCSFactory());
5554

56-
test('Tracker API', () => {
57-
expect(typeof impressionsTrackerFactory).toBe('function'); // The module should return a function which acts as a factory.
58-
59-
const instance = impressionsTrackerFactory(fakeSettings, fakeImpressionsCache, fakeNoneStrategy,strategy, fakeWhenInit);
60-
expect(typeof instance.track).toBe('function'); // The instance should implement the track method which will actually track queued impressions.
61-
});
62-
6355
test('Should be able to track impressions (in DEBUG mode without Previous Time).', () => {
6456
const tracker = impressionsTrackerFactory(fakeSettings, fakeImpressionsCache, fakeNoneStrategy, strategy, fakeWhenInit);
6557

@@ -75,9 +67,9 @@ describe('Impressions Tracker', () => {
7567

7668
expect(fakeImpressionsCache.track).not.toBeCalled(); // cache method should not be called by just creating a tracker
7769

78-
tracker.track([{ imp: imp1 }, { imp: imp2 }, { imp: imp3 }]);
70+
tracker.track([{ imp: imp1 }, { imp: imp2, track: true }, { imp: imp3, track: false }]);
7971

80-
expect(fakeImpressionsCache.track.mock.calls[0][0]).toEqual([imp1, imp2, imp3]); // Should call the storage track method once we invoke .track() method, passing queued params in a sequence.
72+
expect(fakeImpressionsCache.track.mock.calls[0][0]).toEqual([imp1, imp2]); // Should call the storage track method once we invoke .track() method, passing impressions with `track` enabled
8173
});
8274

8375
test('Tracked impressions should be sent to impression listener and integration manager when we invoke .track()', (done) => {
@@ -98,9 +90,9 @@ describe('Impressions Tracker', () => {
9890
expect(fakeIntegrationsManager.handleImpression).not.toBeCalled(); // The integrations manager handleImpression method should not be invoked if we haven't tracked impressions.
9991

10092
// We signal that we actually want to track the queued impressions.
101-
tracker.track([{ imp: fakeImpression }, { imp: fakeImpression2 }], fakeAttributes);
93+
tracker.track([{ imp: fakeImpression }, { imp: fakeImpression2, track: false }], fakeAttributes);
10294

103-
expect(fakeImpressionsCache.track.mock.calls[0][0]).toEqual([fakeImpression, fakeImpression2]); // Even with a listener, impression should be sent to the cache
95+
expect(fakeImpressionsCache.track.mock.calls[0][0]).toEqual([fakeImpression]); // Even with a listener, impressions (with `track` enabled) should be sent to the cache
10496
expect(fakeListener.logImpression).not.toBeCalled(); // The listener should not be executed synchronously.
10597
expect(fakeIntegrationsManager.handleImpression).not.toBeCalled(); // The integrations manager handleImpression method should not be executed synchronously.
10698

@@ -162,7 +154,7 @@ describe('Impressions Tracker', () => {
162154
expect(fakeImpressionsCache.track).not.toBeCalled(); // storage method should not be called until impressions are tracked.
163155

164156
trackers.forEach(tracker => {
165-
tracker.track([{ imp: impression }, { imp: impression2 }, { imp: impression3 }]);
157+
tracker.track([{ imp: impression, track: true }, { imp: impression2 }, { imp: impression3 }]);
166158

167159
const lastArgs = fakeImpressionsCache.track.mock.calls[fakeImpressionsCache.track.mock.calls.length - 1];
168160

0 commit comments

Comments
 (0)