Enzyme: Clean up tests in prep for [email protected]

Created on 30 Jun 2016  路  3Comments  路  Source: enzymejs/enzyme

Based on this twitter thread from dan abramov React 15.2.0 will be adding a warning for props passed through to DOM nodes that aren't DOM attributes.

I don't _think_ this will have any implications on the API of this library. It only would if someone did something like this:

mount(<div foo />);

because we pass the props through, but at that point, that's their fault and issue to fix.

But internally, we do that a lot with our tests (see screenshot below). So effectively we need to update our tests to not put arbitrary props on DOM nodes.

This can be tested currently by installing [email protected]

image

Tests

Most helpful comment

We should just change those to data-amount, data-foo, etc.

All 3 comments

There are a number of boolean HTML attributes that should be totally fine - <input checked /> for example - so hopefully React will maintain a whitelist of these, and not warn for them.

Similarly, any actual HTML attribute without a value, like <div foo>, is sugar for <div foo="foo">, so that warning would be a very bad idea.

If I'm misunderstanding, and it's solely a warning for actually-invalid HTML attribute names, then I'm on board :-)

You nailed it. We just have things like this in our tests <div amount={3} /> which react will warn for. But they do whitelist legitimate attributes.

We should just change those to data-amount, data-foo, etc.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivanbtrujillo picture ivanbtrujillo  路  3Comments

ahuth picture ahuth  路  3Comments

amcmillan01 picture amcmillan01  路  3Comments

timhonders picture timhonders  路  3Comments

mattkauffman23 picture mattkauffman23  路  3Comments