Alexandros K
Alexandros K

Reputation: 947

Jest -- Proper way to write test descriptions

This may seem pedantic but I'm asking from a learner's perspective.

The syntax of the it helper lends itself to the syntax

it('should behave in this certain way...')

and most all the coders I know insist on writing 'should' for every single test.

To me this is a subtle but annoying pet peeve because the whole point of it is to save me keystrokes -- if it comes with the requirement to type should for every test it seems like an utter waste of a shortcut.

Is it a best practice to write it('should...') or can we simply write it('behaves in this expected way')?

Serious question -- I'm losing my mind over this little detail.

Upvotes: 2

Views: 3026

Answers (1)

BrunoLM
BrunoLM

Reputation: 100381

This might be an opinion based question, but I found myself writing a lot of shoulds in the past, until I found a spotify repository that changed my testing life

Should up is a CLI that removes shoulds from your tests and they explain in the README.md why and how you should write tests.

Basically it just removes a lot of text that is just redundant and makes everything easier to read.

Upvotes: 5

Related Questions