Skip to content

Commit

Permalink
chore: add await to useEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Sep 5, 2023
1 parent 59845ea commit 3e3b148
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/plop/tests/action-failure.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
8 changes: 4 additions & 4 deletions packages/plop/tests/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand Down
16 changes: 8 additions & 8 deletions packages/plop/tests/esm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ 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 () => {
const { findByText, userEvent } = await renderPlop([], {
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 () => {
const { findByText, userEvent } = await renderPlop([], {
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 () => {
const { findByText, userEvent } = await renderPlop([], {
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]");
});
16 changes: 8 additions & 8 deletions packages/plop/tests/input-processing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions plop-templates/plop-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
});

0 comments on commit 3e3b148

Please sign in to comment.