Skip to content

Commit f139186

Browse files
committed
Add test for #24
1 parent 4f3f436 commit f139186

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test/browser/experiment.test.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,28 @@ describe('Experiment', function () {
240240
expect(wrapper.find(`#variant-${chosenVariant}`).exists()).toBe(true);
241241
}
242242
});
243+
244+
it('should not not cause an infinite rendering loop when calling setState', () => {
245+
const userIdentifier = UUID();
246+
const experimentName = UUID();
247+
const spy = jest.spyOn(console, 'error');
248+
const App = () => {
249+
const [counter, setCounter] = React.useState(0);
250+
return (
251+
<>
252+
<Experiment name={experimentName} userIdentifier={userIdentifier}>
253+
<Variant name="A">A</Variant>
254+
<Variant name="B">B</Variant>
255+
</Experiment>
256+
257+
<button onClick={() => setCounter(counter + 1)}>
258+
Re-render ({counter})
259+
</button>
260+
</>
261+
);
262+
};
263+
const wrapper = mount(<App />);
264+
wrapper.find('button').simulate('click');
265+
expect(spy).not.toHaveBeenCalled();
266+
});
243267
});

0 commit comments

Comments
 (0)