Skip to content

Commit 21e4ab8

Browse files
committed
add tests
1 parent 33f32b8 commit 21e4ab8

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

packages/remote-config/src/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
7676
/**
7777
* Configures the Remote Config SDK to talk to a local emulator
7878
* instead of product.
79-
*
79+
*
8080
* Must be called before performing any fetches against production
8181
* Remote Config.
8282
*
@@ -85,10 +85,10 @@ export async function activate(remoteConfig: RemoteConfig): Promise<boolean> {
8585
*
8686
* @public
8787
*/
88-
export function connectRemoteConfigEmulator(
88+
export function connectRemoteConfigEmulator(
8989
remoteConfig: RemoteConfig,
9090
url: string
91-
) {
91+
): void {
9292
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
9393

9494
// To avoid the footgun of fetching from prod first,

packages/remote-config/test/remote_config.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,28 @@ describe('RemoteConfig', () => {
518518
);
519519
});
520520
});
521+
522+
describe('connectRemoteConfigEmulator', () => {
523+
it('changes the remote config API URL', () => {
524+
const emulatorUrl = 'http://localhost:9200';
525+
526+
// init storage as if it had never fetched
527+
storageCache.getLastFetchStatus = sinon.stub().returns(undefined);
528+
529+
api.connectRemoteConfigEmulator(rc, emulatorUrl);
530+
expect(window.FIREBASE_REMOTE_CONFIG_URL_BASE === emulatorUrl).to.be.true;
531+
});
532+
533+
it('can not be called if a fetch has already happened', () => {
534+
const emulatorUrl = 'http://localhost:9200';
535+
536+
// init storage as if it had never fetched
537+
storageCache.getLastFetchStatus = sinon.stub().returns('success');
538+
539+
const expectedError = ERROR_FACTORY.create(ErrorCode.ALREADY_FETCHED);
540+
expect(() => api.connectRemoteConfigEmulator(rc, emulatorUrl)).to.throw(
541+
expectedError.message
542+
);
543+
});
544+
});
521545
});

0 commit comments

Comments
 (0)