Hacker News new | ask | show | jobs
by ngcazz 1612 days ago
Using `let` carries the risk of increasing the cognitive load required to understand why a test is failing or passing if it's not used carefully.

- they bring example execution order into play, especially with nested contexts and nested `let`s shadowing other above.

- they invite DRYing up test code, making it really easy to couple unrelated tests together and hard to understand tests in isolation.

- the corollary to the above is creating a brittle test suite. (in any case if DRY is a footgun in production code, it's doubly so in test code.)

- they require you to divert your attention from the examples to see what the states of your test objects are going to be.

These pitfalls can be avoided if, for example, you favor building up your test object graphs inside your examples.

(@r-s That's not the same thing though, they're talking about the eagerly evaluated version of `let`.)