Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 307a713

Browse files
committed
Don't delay resolving promise if the coreJS singleton is overridden (mocked out for test)
1 parent 0b442d6 commit 307a713

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

package/src/services/userfront.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ declare module "@userfront/core" {
1414
}
1515

1616
let singleton = Userfront;
17+
let isSingletonOverridden = false;
1718

1819
/**
1920
* Override the Userfront singleton imported from @userfront/core with an object of your choice.
@@ -22,6 +23,7 @@ let singleton = Userfront;
2223
*/
2324
export const overrideUserfrontSingleton = (newSingleton: any) => {
2425
singleton = newSingleton as typeof Userfront;
26+
isSingletonOverridden = true;
2527
};
2628

2729
// A type with the keys of all functions in Type
@@ -117,6 +119,11 @@ export const callUserfront = async ({ method, args = [] }: CallUserfront) => {
117119
// and for the NEXT event loop cycle to finish,
118120
// then return.
119121
// TODO DEV-658 fix this in a nicer and more reliable way
122+
if (isSingletonOverridden) {
123+
// Don't wait if we've overridden the CoreJS singleton,
124+
// i.e. mocked it out for tests.
125+
return res;
126+
}
120127
return new Promise((resolve) => {
121128
setTimeout(() => resolve(res), 1);
122129
});

0 commit comments

Comments
 (0)