jest: tests running on stale code

2021-07-23

 | 

~1 min read

 | 

84 words

From time to time, Jest’s test runner seems to be stuck on old code. In debugging it, I tried a number of different strategies, but ultimately discovered there’s a clearCache option to the CLI.

Alternatively, I could use the --no-cache flag, however, the docs discourage this in most circumstances.

Since the majority of the time, I like using Jest in its watch mode, I just added a script in my package.json, "test:clean": "jest --clearCache".

Now, I can run that whenever my tests get stale!


Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!