Skip to content

Commit

Permalink
chore: Add a test for user input
Browse files Browse the repository at this point in the history
  • Loading branch information
maiisthebest committed Mar 4, 2024
1 parent 824be43 commit e8b1de9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/RobotApp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const readline = require("readline");

const RobotApp = require("./RobotApp");
const RobotSimulator = require("./RobotSimulator");
const Table = require("./Table");
const Robot = require("./Robot");

jest.mock("readline");

describe("RobotApp", () => {
beforeEach(() => {
readline.createInterface.mockClear();
});

it("should ask for user input", async () => {
const mockQuestion = jest.fn();
readline.createInterface.mockReturnValue({
question: mockQuestion,
on: jest.fn(),
close: jest.fn(),
});

setTimeout(() => mockQuestion.mock.calls[0][1]("PLACE 0,0,NORTH"), 0);

const simulator = new RobotSimulator(new Table(5, 5), new Robot());
const robotApp = new RobotApp(simulator);

robotApp.start();

expect(mockQuestion).toHaveBeenCalledWith(
"Enter a command (or 'q' to quit): ",
expect.anything()
);
});
});

0 comments on commit e8b1de9

Please sign in to comment.