如何使用@ testing-library / react-hooks编写用于React钩子的单元测试用例

时间:2020-04-04 07:12:43

标签: reactjs jestjs react-hooks

const [radioValue, setRadioValue] = React.useState("some_value");
  const radioChange = (event, { value }) => {
    setRadioValue(value);
  };

这就是我的尝试

describe("radioChange", () => {
  it("radioChange on radio button", () => {
    const { result } = renderHook(useAppendValuesState);
    act(() => {
      result.current.radioChange();
    });

    console.log(result);
    expect(result.current.radioValue).toBe("test");
  });
});

获取TypeError:无法读取未定义的属性“值”,请帮忙!

0 个答案:

没有答案