You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Opening this issue as requested by @taion in #3572.
The issue is that the warning added to help prevent accidental rendering of <Link />s outside a router context obscures the results of tests around onClick behavior. For example, both the following tests (where <Link /> is being rendered inside the <Nav /> component) will now result in clickHandler.callCount being 0, so I can't test the difference in behavior depending on the hidden prop:
it('should not call the `clickHandler` function on link click when hidden is true', () => {
const clickHandler = sinon.stub();
const wrapper = mount(<Nav hidden clickHandler={clickHandler} />);
expect(clickHandler.callCount).to.equal(0);
wrapper.find('Link').at(0).simulate('click');
expect(clickHandler.callCount).to.equal(0);
});
it('should call the `clickHandler` function on link click when hidden is false', () => {
const clickHandler = sinon.stub();
const wrapper = mount(<Nav hidden={false} clickHandler={clickHandler} />);
expect(clickHandler.callCount).to.equal(0);
wrapper.find('Link').at(0).simulate('click');
expect(clickHandler.callCount).to.equal(1);
});
A summary of the solutions suggested via discussion in #3572:
perhaps only do the warning if not using NODE_ENV=testing (but this has the disadvantage of not catching some bugs in tests, plus using NODE_ENV=testing is not all that common)
move the warning below the call to external onClick (This gets my vote! I'm already using preventDefault, so that part's not an issue.)
inject a fake router context for tests like this (IMO, this detracts from the minimal test setup approach that Enzyme allows/encourages, but I can see how my usage in this case is not all that typical, so perhaps the burden is on the tester in this situation to do a little more setup.)
The text was updated successfully, but these errors were encountered:
We should move the check to after running the user onClick handler. I was being overzealous. That code needs a bit of cleanup and I'll look at it.
Having to preventDefault in spies here is sort of mediocre. Does Enzyme not give you a way to inject context when you render for tests? It's very easy to do that in teaspoon, which I'm more familiar with.
Opening this issue as requested by @taion in #3572.
The issue is that the warning added to help prevent accidental rendering of
<Link />
s outside a router context obscures the results of tests aroundonClick
behavior. For example, both the following tests (where<Link />
is being rendered inside the<Nav />
component) will now result inclickHandler.callCount
being 0, so I can't test the difference in behavior depending on thehidden
prop:A summary of the solutions suggested via discussion in #3572:
NODE_ENV=testing
(but this has the disadvantage of not catching some bugs in tests, plus usingNODE_ENV=testing
is not all that common)onClick
(This gets my vote! I'm already usingpreventDefault
, so that part's not an issue.)The text was updated successfully, but these errors were encountered: