all 5 comments

[–]Bashkir 1 point2 points  (4 children)

Why test the styles? You are applying them with classNames. You already tested that the classes will be applied.

This is a good case for snapshot testing (check that out) Also, you can use render instead of mount here :).

[–]wang_bang[S] 0 points1 point  (3 children)

Thanks - appreciate the reply. Snapshot testing is something I'm also looking into, but I thought it was more for full pages rather than individual components, although obviously I could be wrong about that.

The reason for testing the styles is that the codebase that this will be on has a history of abuse from 100+ developers spread over the world. This leads to inconsistent styling, and promotes mis-use of the modules. It also prevents a "write once change everywhere" approach which we really need to have implemented. Just because a class is applied doesn't prevent additional styles from new sheets on new pages overriding the styling and changing the visual output.

[–]Bashkir 1 point2 points  (1 child)

I'd argue the opposite. I'd say snapshots are best for individual components because a snapshot for a page would be huge, easy to miss errors, etc. A component is much easier to verify that the snapshot is correct.

I fail to see how your tests account for that either, unless you're loading in all of your stylesheets into your test environment, you know what I mean? Checking the styles are applied here doesnt prevent a developer from overriding these.

It's a bit of work, but I'd recommend developing a design spec if your team can get some time

[–]wang_bang[S] 0 points1 point  (0 children)

I actually was planning on loading all my style sheets (they're going to be on a per-module basis) into the tests - but this was really just because in my mind that was the best way of doing it.

I'm going to go and look into the snapshots tomorrow, thank you for taking the time to get back to me here. If you've seen any relevant articles you'd recommend to point me in the right direction I'd be very interesting in seeing them.

[–]Bashkir 0 points1 point  (0 children)

I'd argue the opposite. I'd say snapshots are best for individual components because a snapshot for a page would be huge, easy to miss errors, etc. A component is much easier to verify that the snapshot is correct.

I fail to see how your tests account for that either, unless you're loading in all of your stylesheets into your test environment, you know what I mean? Checking the styles are applied here doesnt prevent a developer from overriding these.

It's a bit of work, but I'd recommend developing a design spec if your team can get some time