Skip to content

Commit f3acfd9

Browse files
committed
fix: added-unhandled-error-test
1 parent 4ded71a commit f3acfd9

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

test/react.test.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,46 @@ it('should not crash when server returns 500 error', async () => {
230230

231231
// onError callback should have been called
232232
expect(onError).toHaveBeenCalledTimes(1);
233+
});
234+
235+
it('should not throw unhandled promise rejection when server returns 500 error', async () => {
236+
const onChange = jest.fn();
237+
const onError = jest.fn();
238+
const unhandledRejectionHandler = jest.fn();
239+
const { flagsmith, initConfig, mockFetch } = getFlagsmith({
240+
onChange,
241+
onError,
242+
});
243+
window.addEventListener('unhandledrejection', unhandledRejectionHandler);
244+
245+
mockFetch.mockImplementationOnce(() =>
246+
Promise.resolve({
247+
status: 500,
248+
headers: { get: () => null },
249+
text: () => Promise.resolve('API Response: 500')
250+
})
251+
);
252+
253+
expect(() => {
254+
render(
255+
<FlagsmithProvider flagsmith={flagsmith} options={initConfig}>
256+
<FlagsmithPage/>
257+
</FlagsmithProvider>
258+
);
259+
}).not.toThrow();
260+
261+
expect(mockFetch).toHaveBeenCalledTimes(1);
262+
263+
await waitFor(() => {
264+
// Loading should complete with error
265+
const loadingState = JSON.parse(screen.getByTestId("loading-state").innerHTML);
266+
expect(loadingState.isLoading).toBe(false);
267+
expect(loadingState.isFetching).toBe(false);
268+
expect(loadingState.error).toBeTruthy();
269+
});
270+
271+
// onError callback should have been called
272+
expect(onError).toHaveBeenCalledTimes(1);
273+
window.removeEventListener('unhandledrejection', unhandledRejectionHandler);
274+
233275
});

utils/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Auto-generated by write-version.js
2-
export const SDK_VERSION = "9.3.1";
2+
export const SDK_VERSION = "9.3.2";

0 commit comments

Comments
 (0)