Skip to content

Commit b365fd8

Browse files
committed
chore: migrate tests to use better matchers
1 parent fc4bb7f commit b365fd8

File tree

6 files changed

+46
-34
lines changed

6 files changed

+46
-34
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"dependencies": {
4949
"@types/liftoff": "^4.0.0",
5050
"chalk": "^5.0.0",
51-
"cli-testing-library": "^1.0.0-alpha.14",
51+
"cli-testing-library": "^1.0.0-alpha.15",
5252
"interpret": "^2.2.0",
5353
"liftoff": "^4.0.0",
5454
"minimist": "^1.2.5",

tests/actions.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test("Plop to add and rename files", async () => {
1717
cwd: resolve(__dirname, "./examples/add-action"),
1818
});
1919

20-
expect(await findByText("What should the file name be?")).toBeTruthy();
20+
expect(await findByText("What should the file name be?")).toBeInTheConsole();
2121

2222
userEvent.keyboard("new-output");
2323
userEvent.keyboard("[Enter]");
@@ -38,7 +38,7 @@ test("Plop to add and change file contents", async () => {
3838
cwd: resolve(__dirname, "./examples/add-action"),
3939
});
4040

41-
expect(await findByText("What's your name?")).toBeTruthy();
41+
expect(await findByText("What's your name?")).toBeInTheConsole();
4242

4343
userEvent.keyboard("Corbin");
4444
userEvent.keyboard("[Enter]");

tests/esm.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@ test("should load ESM file", async () => {
99
const { findByText, userEvent } = await renderPlop([], {
1010
cwd: resolve(__dirname, "./examples/esm"),
1111
});
12-
expect(await findByText("What is your name?")).toBeTruthy();
12+
expect(await findByText("What is your name?")).toBeInTheConsole();
1313
userEvent.keyboard("Joe");
14-
expect(await findByText("Joe")).toBeTruthy();
14+
expect(await findByText("Joe")).toBeInTheConsole();
1515
userEvent.keyboard("[Enter]");
1616
});
1717

1818
test("should load MJS file", async () => {
1919
const { findByText, userEvent } = await renderPlop([], {
2020
cwd: resolve(__dirname, "./examples/mjs"),
2121
});
22-
expect(await findByText("What is your name?")).toBeTruthy();
22+
expect(await findByText("What is your name?")).toBeInTheConsole();
2323
userEvent.keyboard("Joe");
24-
expect(await findByText("Joe")).toBeTruthy();
24+
expect(await findByText("Joe")).toBeInTheConsole();
2525
userEvent.keyboard("[Enter]");
2626
});
2727

2828
test("should load CJS file", async () => {
2929
const { findByText, userEvent } = await renderPlop([], {
3030
cwd: resolve(__dirname, "./examples/cjs"),
3131
});
32-
expect(await findByText("What is your name?")).toBeTruthy();
32+
expect(await findByText("What is your name?")).toBeInTheConsole();
3333
userEvent.keyboard("Joe");
34-
expect(await findByText("Joe")).toBeTruthy();
34+
expect(await findByText("Joe")).toBeInTheConsole();
3535
userEvent.keyboard("[Enter]");
3636
});
3737

3838
test("should load JS module='commonjs' file", async () => {
3939
const { findByText, userEvent } = await renderPlop([], {
4040
cwd: resolve(__dirname, "./examples/cjs-js"),
4141
});
42-
expect(await findByText("What is your name?")).toBeTruthy();
42+
expect(await findByText("What is your name?")).toBeInTheConsole();
4343
userEvent.keyboard("Joe");
44-
expect(await findByText("Joe")).toBeTruthy();
44+
expect(await findByText("Joe")).toBeInTheConsole();
4545
userEvent.keyboard("[Enter]");
4646
});

tests/input-processing.spec.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ test("should show help information on help flag", async () => {
1717

1818
test("should show version on version flag", async () => {
1919
const { findByText } = await renderPlop(["--version"]);
20-
expect(await findByText(/^[\w\.-]+$/)).toBeTruthy();
20+
expect(await findByText(/^[\w\.-]+$/)).toBeInTheConsole();
2121
});
2222

2323
test("should show version on v flag", async () => {
2424
const { findByText } = await renderPlop(["-v"]);
25-
expect(await findByText(/^[\w\.-]+$/)).toBeTruthy();
25+
expect(await findByText(/^[\w\.-]+$/)).toBeInTheConsole();
2626
});
2727

2828
test("should display inquirer prompts", async () => {
2929
const { findByText, userEvent } = await renderPlop([], {
3030
cwd: resolve(__dirname, "./examples/prompt-only"),
3131
});
32-
expect(await findByText("What is your name?")).toBeTruthy();
32+
expect(await findByText("What is your name?")).toBeInTheConsole();
3333
userEvent.keyboard("Joe");
34-
expect(await findByText("Joe")).toBeTruthy();
34+
expect(await findByText("Joe")).toBeInTheConsole();
3535
userEvent.keyboard("[Enter]");
3636
});
3737

@@ -47,24 +47,26 @@ test("Should handle generator prompt", async () => {
4747
userEvent.keyboard("[ArrowDown]");
4848
userEvent.keyboard("[Enter]");
4949

50-
expect(await findByText("this is a test")).toBeTruthy();
50+
expect(await findByText("this is a test")).toBeInTheConsole();
5151
});
5252

5353
test("Should bypass generator prompt", async () => {
5454
const { findByText } = await renderPlop(["test"], {
5555
cwd: resolve(__dirname, "./examples/javascript"),
5656
});
5757

58-
expect(await findByText("What is your name?")).toBeTruthy();
58+
expect(await findByText("What is your name?")).toBeInTheConsole();
5959
});
6060

6161
test("Should bypass prompt by input", async () => {
6262
const { queryByText, findByText } = await renderPlop(["Frank"], {
6363
cwd: resolve(__dirname, "./examples/prompt-only"),
6464
});
6565

66-
expect(await queryByText("What is your name?")).toBeFalsy();
67-
expect(await findByText("What pizza toppings do you like?")).toBeTruthy();
66+
expect(await queryByText("What is your name?")).not.toBeInTheConsole();
67+
expect(
68+
await findByText("What pizza toppings do you like?")
69+
).toBeInTheConsole();
6870
});
6971

7072
test("Should bypass prompt by input placeholder", async () => {
@@ -75,9 +77,11 @@ test("Should bypass prompt by input placeholder", async () => {
7577
}
7678
);
7779

78-
expect(await findByText("What is your name?")).toBeTruthy();
80+
expect(await findByText("What is your name?")).toBeInTheConsole();
7981
userEvent.keyboard("[Enter]");
80-
expect(await queryByText("What pizza toppings do you like?")).toBeFalsy();
82+
expect(
83+
await queryByText("What pizza toppings do you like?")
84+
).not.toBeInTheConsole();
8185
});
8286

8387
test("Should bypass prompt by name", async () => {
@@ -88,17 +92,21 @@ test("Should bypass prompt by name", async () => {
8892
}
8993
);
9094

91-
expect(await queryByText("What is your name?")).toBeFalsy();
92-
expect(await findByText("What pizza toppings do you like?")).toBeTruthy();
95+
expect(await queryByText("What is your name?")).not.toBeInTheConsole();
96+
expect(
97+
await findByText("What pizza toppings do you like?")
98+
).toBeInTheConsole();
9399
});
94100

95101
test("Should allow for empty string bypassing", async () => {
96102
const { queryByText, findByText } = await renderPlop(["--", "--name", `""`], {
97103
cwd: resolve(__dirname, "./examples/prompt-only"),
98104
});
99105

100-
expect(await queryByText("What is your name?")).toBeFalsy();
101-
expect(await findByText("What pizza toppings do you like?")).toBeTruthy();
106+
expect(await queryByText("What is your name?")).not.toBeInTheConsole();
107+
expect(
108+
await findByText("What pizza toppings do you like?")
109+
).toBeInTheConsole();
102110
});
103111

104112
test.todo("Dynamic actions");

tests/wrapper.spec.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const renderWrapper = (...props) => {
1818
test("wrapper should show version on v flag", async () => {
1919
const { findByText } = await renderWrapper(["-v"]);
2020

21-
expect(await findByText(/^[\w\.-]+$/)).toBeTruthy();
21+
expect(await findByText(/^[\w\.-]+$/)).toBeInTheConsole();
2222
});
2323

2424
test("wrapper should prompts", async () => {
2525
const { findByText, fireEvent } = await renderWrapper([""], {
2626
cwd: resolve(__dirname, "./examples/wrap-plop"),
2727
});
2828

29-
expect(await findByText("What is your name?")).toBeTruthy();
29+
expect(await findByText("What is your name?")).toBeInTheConsole();
3030
});
3131

3232
test("wrapper should bypass prompts with index", async () => {
@@ -37,8 +37,10 @@ test("wrapper should bypass prompts with index", async () => {
3737
}
3838
);
3939

40-
expect(await queryByText("What is your name?")).toBeFalsy();
41-
expect(await findByText("What pizza toppings do you like?")).toBeTruthy();
40+
expect(await queryByText("What is your name?")).not.toBeInTheConsole();
41+
expect(
42+
await findByText("What pizza toppings do you like?")
43+
).toBeInTheConsole();
4244
});
4345

4446
test("wrapper should bypass prompts with name", async () => {
@@ -49,8 +51,10 @@ test("wrapper should bypass prompts with name", async () => {
4951
}
5052
);
5153

52-
expect(await queryByText("What is your name?")).toBeFalsy();
53-
expect(await findByText("What pizza toppings do you like?")).toBeTruthy();
54+
expect(await queryByText("What is your name?")).not.toBeInTheConsole();
55+
expect(
56+
await findByText("What pizza toppings do you like?")
57+
).toBeInTheConsole();
5458
});
5559

5660
test("can run actions (add)", async () => {

0 commit comments

Comments
 (0)