Skip to content

Commit 40f3e19

Browse files
committed
fix(the-typeinator): address PR feedback for syntactic-sugar test
- Use jest.fn() instead of manual array for cleaner assertions - Add missing machine objects to fix test failures - Support TEST_SOLUTIONS environment variable
1 parent 65d5a7e commit 40f3e19

File tree

1 file changed

+18
-15
lines changed
  • projects/from-javascript-to-typescript/the-typeinator/01-syntactic-sugar

1 file changed

+18
-15
lines changed
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
const { announceMachines } = require("./index");
1+
const index = require("./index");
2+
const solution = require("./solution");
3+
const { announceMachines } = process.env.TEST_SOLUTIONS ? solution : index;
24

3-
test("announceMachines returns correct count", () => {
4-
const messages = [];
5+
describe("01 - Syntactic Sugar > announceMachines", () => {
6+
test("announces the expected label and categories", () => {
7+
const announce = jest.fn();
58

6-
const result = announceMachines(
7-
(msg) => messages.push(msg),
8-
{ make: "Honda", model: "Civic" },
9-
{ make: "Toyota", model: "Corolla", label: "Compact Car" },
10-
{ make: "Ford", model: "Focus", label: "Eco Car" },
11-
);
9+
const result = announceMachines(
10+
announce,
11+
{ make: "Honda", model: "Civic" },
12+
{ label: "Compact Car" },
13+
{ label: "Eco Car" },
14+
);
1215

13-
expect(result).toBe(2);
14-
expect(messages).toEqual([
15-
"Make: Honda Model: Civic",
16-
"Compact Car",
17-
"Eco Car",
18-
]);
16+
expect(announce.mock.calls).toEqual([
17+
["Make: Honda; Model: Civic"],
18+
["Compact Car"],
19+
["Eco Car"],
20+
]);
21+
});
1922
});

0 commit comments

Comments
 (0)