Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

renderHook unable to rerender props on the wrapper

未关闭
#1,372 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, react
领域
documentation

调研方向

首先,将当前的 renderHook wrapper 和 rerender 行为与链接的 react-hooks-testing-library context 示例进行比较。确定是否可以更新 wrapper props,或者文档是否需要提供替代方案;存在受支持的方法,或存在附带示例且有明确文档说明的限制,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

Sorry I don't know if I should list this as a bug or as a feature request with the renderHook now being supported react hook testing library. It used to possible to test how context and hooks worked together with react-hooks-testing library - you could render a wrapper with and initial props and then pass new props to the wrapper using rerender.

Here is the example on react hooks testing library site

This was really useful as it allowed you to test how updates from your providers via context could effect the output from your hooks.

To Reproduce Steps to reproduce the behaviour:
This is the implementation as it was on react hooks testing library - I do understand how that how the initial props for the wrapper as changed but I'm using this more to draw attention to how rerender used to work.

import { renderHook, act } from '@testing-library/react-hooks'
import { CounterStepProvider, useCounter } from './counter'

test('should use custom step when incrementing', () => {
  const wrapper = ({ children, step }) => (
    <CounterStepProvider step={step}>{children}</CounterStepProvider>
  )
  const { result, rerender } = renderHook(() => useCounter(), {
    wrapper,
    initialProps: {
      step: 2
    }
  })

  act(() => {
    result.current.increment()
  })

  expect(result.current.count).toBe(2)

  /**
   * For react hook testing library this could be use to update the provider props and therefore affect a hooks return values via context
   * in react testing library these values seem to be just passed to the renderHook callback
   */
  rerender({ step: 8 })

  act(() => {
    result.current.increment()
  })

  expect(result.current.count).toBe(10)
})

Expected behaviour
There should be some way to rerender the wrapper for the hook you are testing with different prop values or maybe a documented example of how to test context and hooks in this way if it already exists. Is this possible with the current implementation?

主要语言
JavaScript
星标
479
派生
738
平均合并
5 天 1 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

testing-library/testing-library-docs 的其他 Issue

查看 testing-library/testing-library-docs 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。