Skip to content

Commit

Permalink
Add test for #24
Browse files Browse the repository at this point in the history
  • Loading branch information
moretti committed May 29, 2021
1 parent 4f3f436 commit f139186
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/browser/experiment.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,28 @@ describe('Experiment', function () {
expect(wrapper.find(`#variant-${chosenVariant}`).exists()).toBe(true);
}
});

it('should not not cause an infinite rendering loop when calling setState', () => {
const userIdentifier = UUID();
const experimentName = UUID();
const spy = jest.spyOn(console, 'error');
const App = () => {
const [counter, setCounter] = React.useState(0);
return (
<>
<Experiment name={experimentName} userIdentifier={userIdentifier}>
<Variant name="A">A</Variant>
<Variant name="B">B</Variant>
</Experiment>

<button onClick={() => setCounter(counter + 1)}>
Re-render ({counter})
</button>
</>
);
};
const wrapper = mount(<App />);
wrapper.find('button').simulate('click');
expect(spy).not.toHaveBeenCalled();
});
});

0 comments on commit f139186

Please sign in to comment.