Skip to content

Return value of hook run with testHook? #295

Closed
@danielkcz

Description

@danielkcz

Honestly, it got me confused big time. Considering that most of the tests might actually want to validate the output of the custom hook I find it strange we need to do this.

  test('accepts a default initial value for `count`', () => {
    let count
    testHook(() => ({count} = useCounter({})))

    expect(count).toBe(0)
  })

So I would like to propose getting the output directly.

  test('accepts a default initial value for `count`', () => {
    const { result } = testHook(() => useCounter({}))

    expect(result.count).toBe(0)
  })

It can be compared to a render where we are getting container (and bunch of getters) to write our expectations. The testHook is kinda inconsistent in this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions