I'm trying to write more unit tests for my combobox component, but more specifically, I want to simulate keyboard input into the combobox. I've tried using React's testing library's keyboard events (ex: fireEvent.keyDown) but when I debug after firing the event, the input value never changes.
Ideally, I'd like to use React's testing library in my unit tests, but if there's something else that's easier, I'd be open to it.
Basically, all I want to know is: how do I write unit tests for the basic functionalities of my combobox component??
EDIT: now I can't get the unit test to work if I set autoComplete to "off" in the ComboBox props. I've tried keyDown on "A" followed by keyDown on "Enter" and "Tab" but to no avail. Updated code snippet below.
const dropdownOptions: IComboBoxOption[] = [{ key: "A", text: "A" }, { key: "B", text: "B" }];
const dropdown = <ComboBox options = { dropdownOptions } autoComplete = { "off" }></ComboBox>
//in the unit test
it("Should change input using keyboard events", () => {
const { getByRole } = render(dropdown);
const inputNode = getByRole("combobox");
fireEvent.keyDown(inputNode, { key: "A", code: "KeyA" });
expect(inputNode.getAttribute("value")).toBe("A");
})