ava: afterEach and beforeEach not running?
I’ve reproduced this bug in this repo. From the README there:
The
testdirectory has abug.jsand aworkaround.js.If you run:
npm installand thennpm tyou’ll get:~/Developer/ava-beforeEach-afterEach-bug (master) ⛄ $ npm run test -s ✔ workaround › first log ✔ workaround › second log ✔ bug › first log ✖ bug › second log t.true(console.log.calledOnce) | false 1 test failed 1. second log AssertionError: false === true Test.fn (test/bug.js:16:3)For some reason, it appears that perhaps the cleanup function is not run between the two test runs.
It’s using the latest version of AVA. Specifically, I spotted this here. Let me know if you need more info!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 18 (17 by maintainers)
@kentcdodds They don’t require that tests run serially. It’s because
console.logis global, so shared between the two tests. This means thatconsole.logis referring to the same spy. So in this situation, it’s necessary to run them serially. If you are able (which is not the case here) to use thecontextobject, you don’t have to run them serially because it’s a totally new object.Shared variable
Output:
Context variable
Output:
They are, but AVA is just too fast 😃.
Look at the execution flow
As you see, the
console.logwill be the same forfirstandsecond, being the one created in the second call tobeforeEach. So yes, they are shared 😃.Exactly. From the moment you have something shared (which might not seem to be shared in the first place), you will have to execute them serially.
@SamVerschueren On a side note, the above would be great as a recipe. Hint hint 😉