Skip to content

Commit 8c5d522

Browse files
authored
Try to fix flaky analytics test (#3612)
1 parent 61b4cd3 commit 8c5d522

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

packages/analytics/index.test.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ describe('FirebaseAnalytics instance tests', () => {
8787
analyticsInstance.logEvent(EventName.ADD_PAYMENT_INFO, {
8888
currency: 'USD'
8989
});
90-
// Clear event stack of async FID call.
91-
// For IE: Need then() or else "expect" runs immediately on FID resolve
92-
// before the other statements in initializeGAId.
93-
await fidDeferred.promise.then();
90+
// Clear event stack of initialization promise.
91+
const { initializedIdPromisesMap } = getGlobalVars();
92+
await Promise.all(Object.values(initializedIdPromisesMap));
9493
expect(gtagStub).to.have.been.calledWith('js');
9594
expect(gtagStub).to.have.been.calledWith(
9695
GtagCommand.CONFIG,
@@ -101,10 +100,6 @@ describe('FirebaseAnalytics instance tests', () => {
101100
update: true
102101
}
103102
);
104-
// Clear event stack of initialization promise.
105-
const { initializedIdPromisesMap } = getGlobalVars();
106-
await Promise.all(Object.values(initializedIdPromisesMap));
107-
// await Promise.resolve().then(() => {});
108103
expect(gtagStub).to.have.been.calledWith(
109104
GtagCommand.EVENT,
110105
EventName.ADD_PAYMENT_INFO,
@@ -159,10 +154,9 @@ describe('FirebaseAnalytics instance tests', () => {
159154
analyticsInstance.logEvent(EventName.ADD_PAYMENT_INFO, {
160155
currency: 'USD'
161156
});
162-
// Clear event stack of async FID call.
163-
// For IE: Need then() or else "expect" runs immediately on FID resolve
164-
// before the other statements in initializeGAId.
165-
await fidDeferred.promise.then();
157+
// Clear event stack of initialization promise.
158+
const { initializedIdPromisesMap } = getGlobalVars();
159+
await Promise.all(Object.values(initializedIdPromisesMap));
166160
expect(gtagStub).to.have.been.calledWith('js');
167161
expect(gtagStub).to.have.been.calledWith(
168162
GtagCommand.CONFIG,
@@ -173,9 +167,6 @@ describe('FirebaseAnalytics instance tests', () => {
173167
update: true
174168
}
175169
);
176-
// Clear event stack of initialization promise.
177-
const { initializedIdPromisesMap } = getGlobalVars();
178-
await Promise.all(Object.values(initializedIdPromisesMap));
179170
expect(gtagStub).to.have.been.calledWith(
180171
GtagCommand.EVENT,
181172
EventName.ADD_PAYMENT_INFO,

0 commit comments

Comments
 (0)