Skip to content

samouss/enzyme-setstate-null

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enzyme setState return null

This is a reproduction for the issue #1643.

When returning null from setState Enzyme still trigger a render.

Install

yarn && yarn test

Test case

See Counter.js & Counter.test.js:

it('expect to increment until 3', () => {
  const children = jest.fn(() => null);

  const wrapper = shallow(<Counter>{children}</Counter>);

  expect(children).toHaveBeenCalledTimes(1);

  lastArgs(children).increment(); // 0 > 2 => false update

  expect(children).toHaveBeenCalledTimes(2);

  lastArgs(children).increment(); // 1 > 2 => false update

  expect(children).toHaveBeenCalledTimes(3);

  lastArgs(children).increment(); // 2 > 2 => false update

  expect(children).toHaveBeenCalledTimes(4);

  lastArgs(children).increment(); // 3 > 2 => true prevent update

  // This assertion expect to pass but Enzyme render
  // even when we return `null` from setState.
  expect(children).toHaveBeenCalledTimes(4);
});

About

Example of a Enzyme re-render with setState

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published