Skip to content

Add updateWithAct to render #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

ccfz
Copy link

@ccfz ccfz commented Apr 3, 2019

Summary

To test behaviour that only occurs when props are updated it is
necessary to call update on the test instance. However, if the
behaviour under test is triggered by a hook, e.g. useEffect then
the test will fail because the hook is only triggered after the test
has run.

#111

Test plan

describe('when FloatLabel becomes active', () => {
  it('updates the Text color from dark to light', () => {
    const wrapper = render(<FloatLabel active={false} />)

    expect(expect(text.props.style).toMatchObject({ color: 'white' });)

    act(() => wrapper.update(<FloatLabel active />));
   // with the changes it will simply work by calling update

    expect(text.props.style).toMatchObject({ color: 'white' });
  });
});

To test behaviour that only occurs when props are updated it is
necessary to call update on the test instance. However, if the
behaviour under test is triggered by a hook, e.g. useEffect then
the test will fail because the hook is only triggered after the test
has run.

This addresses the issue by wrapping the update function with act().

callstack#111
@thymikee
Copy link
Member

thymikee commented Apr 3, 2019

Thank you! If you rebased to latest master, you'd see this is already fixed by #137 and released as 1.6.2 just now :)

Looking forward to future contributions!

@thymikee thymikee closed this Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants