diff --git a/gbajs3/src/components/modals/upload-cheats.spec.tsx b/gbajs3/src/components/modals/upload-cheats.spec.tsx
index 3656d8c2..4019ac9f 100644
--- a/gbajs3/src/components/modals/upload-cheats.spec.tsx
+++ b/gbajs3/src/components/modals/upload-cheats.spec.tsx
@@ -52,7 +52,10 @@ describe('', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));
expect(uploadCheatsSpy).toHaveBeenCalledOnce();
- expect(uploadCheatsSpy).toHaveBeenCalledWith(testCheatFile);
+ expect(uploadCheatsSpy).toHaveBeenCalledWith(
+ testCheatFile,
+ expect.anything()
+ );
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();
expect(screen.getByText('Upload complete!')).toBeVisible();
@@ -105,8 +108,14 @@ describe('', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));
expect(uploadCheatsSpy).toHaveBeenCalledTimes(2);
- expect(uploadCheatsSpy).toHaveBeenCalledWith(testCheatFiles[0]);
- expect(uploadCheatsSpy).toHaveBeenCalledWith(testCheatFiles[1]);
+ expect(uploadCheatsSpy).toHaveBeenCalledWith(
+ testCheatFiles[0],
+ expect.anything()
+ );
+ expect(uploadCheatsSpy).toHaveBeenCalledWith(
+ testCheatFiles[1],
+ expect.anything()
+ );
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();
expect(screen.getByText('Upload complete!')).toBeVisible();
diff --git a/gbajs3/src/components/modals/upload-cheats.tsx b/gbajs3/src/components/modals/upload-cheats.tsx
index 8c61980b..8cd9ff07 100644
--- a/gbajs3/src/components/modals/upload-cheats.tsx
+++ b/gbajs3/src/components/modals/upload-cheats.tsx
@@ -42,8 +42,16 @@ export const UploadCheatsModal = () => {
[reset, setValue]
);
- const onSubmit: SubmitHandler = ({ cheatFiles }) => {
- cheatFiles.forEach((cheatFiles) => emulator?.uploadCheats(cheatFiles));
+ const onSubmit: SubmitHandler = async ({ cheatFiles }) => {
+ await Promise.all(
+ cheatFiles.map(
+ (cheatFile) =>
+ new Promise((resolve) => {
+ emulator?.uploadCheats(cheatFile, resolve);
+ })
+ )
+ );
+
reset();
syncActionIfEnabled();
};
diff --git a/gbajs3/src/components/modals/upload-saves.spec.tsx b/gbajs3/src/components/modals/upload-saves.spec.tsx
index c2888ba7..d90d6414 100644
--- a/gbajs3/src/components/modals/upload-saves.spec.tsx
+++ b/gbajs3/src/components/modals/upload-saves.spec.tsx
@@ -51,7 +51,10 @@ describe('', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));
expect(uploadSaveOrSaveStateSpy).toHaveBeenCalledOnce();
- expect(uploadSaveOrSaveStateSpy).toHaveBeenCalledWith(testSaveFile);
+ expect(uploadSaveOrSaveStateSpy).toHaveBeenCalledWith(
+ testSaveFile,
+ expect.anything()
+ );
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();
expect(screen.getByText('Upload complete!')).toBeVisible();
@@ -104,8 +107,14 @@ describe('', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));
expect(uploadSaveSpy).toHaveBeenCalledTimes(2);
- expect(uploadSaveSpy).toHaveBeenCalledWith(testSaveFiles[0]);
- expect(uploadSaveSpy).toHaveBeenCalledWith(testSaveFiles[1]);
+ expect(uploadSaveSpy).toHaveBeenCalledWith(
+ testSaveFiles[0],
+ expect.anything()
+ );
+ expect(uploadSaveSpy).toHaveBeenCalledWith(
+ testSaveFiles[1],
+ expect.anything()
+ );
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();
expect(screen.getByText('Upload complete!')).toBeVisible();
diff --git a/gbajs3/src/components/modals/upload-saves.tsx b/gbajs3/src/components/modals/upload-saves.tsx
index 33bff3e2..a0ca300e 100644
--- a/gbajs3/src/components/modals/upload-saves.tsx
+++ b/gbajs3/src/components/modals/upload-saves.tsx
@@ -45,8 +45,16 @@ export const UploadSavesModal = () => {
[reset, setValue]
);
- const onSubmit: SubmitHandler = ({ saveFiles }) => {
- saveFiles.forEach((saveFile) => emulator?.uploadSaveOrSaveState(saveFile));
+ const onSubmit: SubmitHandler = async ({ saveFiles }) => {
+ await Promise.all(
+ saveFiles.map(
+ (saveFile) =>
+ new Promise((resolve) => {
+ emulator?.uploadSaveOrSaveState(saveFile, resolve);
+ })
+ )
+ );
+
reset();
syncActionIfEnabled();
};