Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ready not emitted when bootstrap is set and bootrstrapOverride is false #200

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1666,3 +1666,52 @@ test('Should set sdkState to healthy when client is started', (done) => {
done();
});
});

describe('READY event emission', () => {
let client: UnleashClient;

const config: IConfig = {
url: 'http://localhost/test',
clientKey: '12',
appName: 'web',
bootstrap: [
{
enabled: false,
name: 'test-frontend',
variant: { name: 'some-variant', enabled: false },
impressionData: false,
},
],
bootstrapOverride: false,
ivarconr marked this conversation as resolved.
Show resolved Hide resolved
fetch: async () => {
return {
ok: true,
headers: new Map(),
async json() {
return {};
},
};
},
};

beforeEach(() => {
fetchMock.resetMocks();
client = new UnleashClient(config);
jest.spyOn(client, 'emit');
});

test('should emit READY when response is OK and not 304, and conditions are met', async () => {
// Mock a successful fetch response that is not 304
fetchMock.mockResponseOnce(
JSON.stringify({
toggles: [{ feature: 'test-feature', enabled: true }],
}),
{
status: 200,
headers: { ETag: 'new-etag' },
}
);

expect(client.emit).toHaveBeenCalledWith(EVENTS.READY);
});
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class UnleashClient extends TinyEmitter {
this.sdkState = 'healthy';
}

if (!this.bootstrap && !this.readyEventEmitted) {
if (!this.readyEventEmitted) {
this.emit(EVENTS.READY);
this.readyEventEmitted = true;
}
Expand Down
Loading