如何用玩笑测试useDispatch调用?

时间:2019-12-16 17:51:44

标签: javascript reactjs testing redux jestjs

我要测试的代码是:

dict.entry(&String::from(key))

当前测试:

const handleChecked = (event: React.SyntheticEvent): void => {
    const { name } = event.currentTarget as HTMLInputElement;
    const id = +name;
    dispatch(checkUncheckCustomer(id));
};

它在应用程序中有效,但在测试中我得到:

it('should check/uncheck customer', () => {
    const customer = wrapper
      .find('.customersList .list li')
      .first()
      .find('.checkbox-custom');
    customer.simulate('click');
    const dispatch = jest.fn(useDispatch);
    const id = mockCustomersList[0].id;
    expect(dispatch).toHaveBeenCalledTimes(1);
    expect(dispatch).toHaveBeenCalledWith(checkUncheckCustomer(id));
});

0 个答案:

没有答案