1

我有一个自定义钩子,如果在执行钩子时满足条件,它会抛出错误。我想测试是否抛出了错误,所以如果抛出错误,测试应该通过。

我尝试将 Hook 包装在 中Error Boundary,但 result.error 未定义。那么如何测试是否引发了错误react-hooks-testing-library

test('it should not be possible to group values by week', () => {
    // Arrange
    const registrations = registrations
    const startDate = moment('2019-11-01')
    const endDate = moment('2019-11-30')
    const groupBy = GroupBy.Week

    // Act
    const { result } = renderHook(
        () => useSingleValueChartData(registrations, startDate, endDate, groupBy),
        { wrapper: AppErrorBoundary }
    )
    // this passes but I would rather test that result.error was defined
    expect(result.error).not.toBeDefined()
})
4

0 回答 0