Create-react-app: Why are "describe" blocks in tests not recommended ?

Created on 5 Sep 2016  路  2Comments  路  Source: facebook/create-react-app

Hi,

I'm curious about this sentence in the docs :

You may optionally wrap them in describe() blocks for logical grouping but this is neither required nor recommended.

Why are describe blocks not recommended? Or is this just a "neutral" not recommended?

Note that I don't particularly disagree with it, it's just that I personally like nested tests and I'm open to change my habits if there are drawbacks to nested tests.

Most helpful comment

Here's my understanding on describe. It was introduced when JavaScript world didn't have the concept of modules and most people implemented everything into one or a few big js files and test files. This ended up being very useful to test multiple parts of the system that were bundled together.

Today, the JS world shifted towards common-js modules and implement one feature/component per file. So what I've been seeing in practice is that most test files have only one describe block that is basically the name of the file itself. So it ends up being noise by adding a mysterious call and having everything indented one way for no good reason.

There aren't a lot of cases where many describes are used anymore. For those cases, you may want to split them into multiple test files or just use describe (which is not banned and still works). But that's now the minority use cases and not the standard way of doing things.

All 2 comments

Nested blocks often lead to confusing code. We don't have a strong opinion on this though.

With some other runners/reporters describe-less it() blocks may not be very usable but this isn't a problem because it prints the filenames. So we encourage folks to try describe-less first.

Here's my understanding on describe. It was introduced when JavaScript world didn't have the concept of modules and most people implemented everything into one or a few big js files and test files. This ended up being very useful to test multiple parts of the system that were bundled together.

Today, the JS world shifted towards common-js modules and implement one feature/component per file. So what I've been seeing in practice is that most test files have only one describe block that is basically the name of the file itself. So it ends up being noise by adding a mysterious call and having everything indented one way for no good reason.

There aren't a lot of cases where many describes are used anymore. For those cases, you may want to split them into multiple test files or just use describe (which is not banned and still works). But that's now the minority use cases and not the standard way of doing things.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alleroux picture alleroux  路  3Comments

fson picture fson  路  3Comments

stopachka picture stopachka  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

DaveLindberg picture DaveLindberg  路  3Comments