Skip to content

Commit 895b1a5

Browse files
author
Chance Strickland
committed
Add tests for invalid input entry to Minutes
1 parent 6500043 commit 895b1a5

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/Minutes.test.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,36 @@ describe("<Minutes />", () => {
4949
});
5050
});
5151

52-
it("should update when the user types a valid value", () => {
53-
let { getByRole } = ReactTestingLibrary.render(
54-
<MinutesWithState defaultValue={5} />
55-
);
56-
let input = getByRole("textbox");
52+
describe("when typing a valid value into the input", () => {
53+
it("should update the input", () => {
54+
let { getByRole } = ReactTestingLibrary.render(
55+
<MinutesWithState defaultValue={5} />
56+
);
57+
let input = getByRole("textbox");
5758

58-
userEvent.type(input, "{backspace}");
59-
userEvent.type(input, "10");
59+
userEvent.type(input, "{backspace}");
60+
userEvent.type(input, "10");
6061

61-
expect(input.value).toBe(String(10));
62+
expect(input.value).toBe(String(10));
63+
});
64+
});
65+
66+
describe("when typing an invalid value into the input", () => {
67+
it("should NOT update the input", () => {
68+
let { getByRole } = ReactTestingLibrary.render(
69+
<MinutesWithState defaultValue={5} />
70+
);
71+
let input = getByRole("textbox");
72+
73+
userEvent.type(input, "{backspace}");
74+
userEvent.type(input, "poop");
75+
76+
expect(input.value).toBe(String(0));
77+
78+
userEvent.type(input, "poop5 oopps");
79+
80+
expect(input.value).toBe(String(5));
81+
});
6282
});
6383
});
6484
});

0 commit comments

Comments
 (0)