From 3e3b148a6def78bafdfef2c3efb3ce01c3f7aaf1 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Tue, 5 Sep 2023 00:34:17 -0700 Subject: [PATCH] chore: add await to useEvents --- packages/plop/tests/action-failure.spec.js | 4 ++-- packages/plop/tests/actions.spec.js | 8 ++++---- packages/plop/tests/esm.spec.js | 16 ++++++++-------- packages/plop/tests/input-processing.spec.js | 16 ++++++++-------- plop-templates/plop-test.js | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/plop/tests/action-failure.spec.js b/packages/plop/tests/action-failure.spec.js index 42c1de5b..f0654647 100644 --- a/packages/plop/tests/action-failure.spec.js +++ b/packages/plop/tests/action-failure.spec.js @@ -11,9 +11,9 @@ test("should exit with code 1 when failed actions", async () => { cwd: resolve(__dirname, "./examples/action-failure"), }); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("Joe"); + await userEvent.keyboard("Joe"); expect(await findByText("Joe")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); const actionOutput = await findByText("Action failed"); await waitFor(() => expect(actionOutput.hasExit()).toStrictEqual({ exitCode: 1 }), diff --git a/packages/plop/tests/actions.spec.js b/packages/plop/tests/actions.spec.js index a2bb1bf3..6d147485 100644 --- a/packages/plop/tests/actions.spec.js +++ b/packages/plop/tests/actions.spec.js @@ -19,8 +19,8 @@ test("Plop to add and rename files", async () => { expect(await findByText("What should the file name be?")).toBeInTheConsole(); - userEvent.keyboard("new-output"); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("new-output"); + await userEvent.keyboard("[Enter]"); await waitFor(() => fs.promises.stat(expectedFilePath)); @@ -40,8 +40,8 @@ test("Plop to add and change file contents", async () => { expect(await findByText("What's your name?")).toBeInTheConsole(); - userEvent.keyboard("Corbin"); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("Corbin"); + await userEvent.keyboard("[Enter]"); await waitFor(() => fs.promises.stat(expectedFilePath)); diff --git a/packages/plop/tests/esm.spec.js b/packages/plop/tests/esm.spec.js index 0569bfc4..9d0381a0 100644 --- a/packages/plop/tests/esm.spec.js +++ b/packages/plop/tests/esm.spec.js @@ -10,9 +10,9 @@ test("should load ESM file", async () => { cwd: resolve(__dirname, "./examples/esm"), }); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("Joe"); + await userEvent.keyboard("Joe"); expect(await findByText("Joe")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); }); test("should load MJS file", async () => { @@ -20,9 +20,9 @@ test("should load MJS file", async () => { cwd: resolve(__dirname, "./examples/mjs"), }); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("Joe"); + await userEvent.keyboard("Joe"); expect(await findByText("Joe")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); }); test("should load CJS file", async () => { @@ -30,9 +30,9 @@ test("should load CJS file", async () => { cwd: resolve(__dirname, "./examples/cjs"), }); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("Joe"); + await userEvent.keyboard("Joe"); expect(await findByText("Joe")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); }); test("should load JS module='commonjs' file", async () => { @@ -40,7 +40,7 @@ test("should load JS module='commonjs' file", async () => { cwd: resolve(__dirname, "./examples/cjs-js"), }); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("Joe"); + await userEvent.keyboard("Joe"); expect(await findByText("Joe")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); }); diff --git a/packages/plop/tests/input-processing.spec.js b/packages/plop/tests/input-processing.spec.js index 97cdf2b7..78b3b11d 100644 --- a/packages/plop/tests/input-processing.spec.js +++ b/packages/plop/tests/input-processing.spec.js @@ -32,9 +32,9 @@ test("should display inquirer prompts", async () => { cwd: resolve(__dirname, "./examples/prompt-only"), }); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("Joe"); + await userEvent.keyboard("Joe"); expect(await findByText("Joe")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); }); test("Should handle generator prompt", async () => { @@ -45,9 +45,9 @@ test("Should handle generator prompt", async () => { await findByText("Please choose a generator"); clear(); - userEvent.keyboard("[ArrowUp]"); - userEvent.keyboard("[ArrowDown]"); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[ArrowUp]"); + await userEvent.keyboard("[ArrowDown]"); + await userEvent.keyboard("[Enter]"); expect(await findByText("this is a test")).toBeInTheConsole(); }); @@ -80,7 +80,7 @@ test("Should bypass input prompt with placeholder", async () => { ); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); expect( await queryByText("What pizza toppings do you like?"), ).not.toBeInTheConsole(); @@ -142,7 +142,7 @@ test("Should bypass checkbox prompt with name", async () => { ); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); expect( await queryByText("What pizza toppings do you like?"), ).not.toBeInTheConsole(); @@ -157,7 +157,7 @@ test("Should bypass checkbox prompt with empty string", async () => { ); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); expect( await queryByText("What pizza toppings do you like?"), ).not.toBeInTheConsole(); diff --git a/plop-templates/plop-test.js b/plop-templates/plop-test.js index 870cb42a..0e5d47a0 100644 --- a/plop-templates/plop-test.js +++ b/plop-templates/plop-test.js @@ -10,7 +10,7 @@ test("should load ESM file", async () => { cwd: resolve(__dirname, "./examples/esm"), }); expect(await findByText("What is your name?")).toBeInTheConsole(); - userEvent.keyboard("Joe"); + await userEvent.keyboard("Joe"); expect(await findByText("Joe")).toBeInTheConsole(); - userEvent.keyboard("[Enter]"); + await userEvent.keyboard("[Enter]"); });