Documentation in regards to Test Environment
See original GitHub issueš Feature Proposal
(Possibly not a feature proposal, but also not a bug per se)
Having recently invested time in understanding Jest properly, one of the hardest concepts to understand was the term ātest environmentā. This was especially hard in relation to these configuration options:
globalSetup: './globalSetup.js',
globalTeardown: './globalTeardown.js',
testEnvironment: './myTestEnvironment',
setupFiles: ['./setupFiles'],
setupFilesAfterEnv: ['./setupFilesAfterEnv'],
For reference, it is good to explain some terminology:
test file testA.test.js
test case test() # or it()
test suite describe()
(I am not sure this is true. Reason is that the documentation seems to use the word ātest fileā and ātest suiteā interchangeably but actually always mean ātest fileā. Never seen describe() referred specifically to ātest suiteā in the Jest documentation, so maybe it isnāt a test suite?)
The problem I had with the documentation
If we take these terms, together with the ātest environmentā term and the above configuration options, I found some parts of the documentation ambiguous.
https://jestjs.io/docs/en/configuration#setupfiles-array
Since every test runs in its own environment,
Concern: It should probably say āevery test fileā instead of āevery testā. Refer to terminology above.
https://jestjs.io/docs/en/configuration#setupfilesafterenv-array
A list of paths to modules that run some code to configure or set up the testing framework before each test.
Concern: It should probably say ābefore each test fileā instead of ābefore each testā. Refer to terminology above.
https://jestjs.io/docs/en/configuration#globalsetup-string
This option allows the use of a custom global setup module which exports an async function that is triggered once before all test suites.
Concern: Not sure what to write here, but ābefore all test suitesā can be interpreted in various ways as a test suite can be considered a describe()
block.
Solution proposal
It would be good to go through both the Configuring Jest and Jest CLI Options documentation, and possible all other docs, to align this properly.
I also think that in general, having a completely specific section (possibly as a guide) describing what a test environment is and how it relates to the above specified configuration options would be great. The way I learnt was to setup a project and testing all these files with a bunch of console.log to actually see what happened.
Motivation
To make it easier for newcomers to understand Jest and how to extend its functionality.
Pitch
It belongs in the main Jest documentation as that is what users refer to when learning Jest.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top GitHub Comments
The bot runs every 10 minutes, doesnāt react to the comment event š
But yes, we should explain this better
unstale