diff --git a/package.json b/package.json index e43bd64..258f3b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unleash-proxy-client", - "version": "2.4.2", + "version": "2.4.3", "description": "A browser client that can be used together with the unleash-proxy.", "main": "./build/index.js", "types": "./build/index.d.ts", diff --git a/src/index.test.ts b/src/index.test.ts index bdb1a39..ecf41e5 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1407,3 +1407,19 @@ test('Should be able to configure UnleashClient with a URL instance', () => { const client = new UnleashClient(config); expect(client).toHaveProperty('url', url); }); + +test("Should update toggles even when refresh interval is set to '0'", async () => { + fetchMock.mockResponse(JSON.stringify(data)); + const config: IConfig = { + url: 'http://localhost/test', + clientKey: '12', + appName: 'web', + refreshInterval: 0, + }; + const client = new UnleashClient(config); + await client.start(); + expect(fetchMock).toHaveBeenCalledTimes(1); + + await client.updateContext({ userId: '123' }); + expect(fetchMock).toHaveBeenCalledTimes(2); +}); diff --git a/src/index.ts b/src/index.ts index 3f8be32..ae593af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -246,9 +246,9 @@ export class UnleashClient extends TinyEmitter { }; this.context = { ...staticContext, ...context }; - if (this.timerRef) { + if (this.timerRef || this.readyEventEmitted) { await this.fetchToggles(); - } else if(this.started) { + } else if (this.started) { await new Promise((resolve) => { const listener = () => { this.fetchToggles().then(() => {