jest: Describe, bail and each don't work as written in the doc
š Bug Report
Describe doesnāt start a test suite, bail doesnāt stop the tests after a fail, each doesnāt format names correctly, and jest output is so verbose that it overflows my terminal.
To Reproduce
git clone https://github.com/Sharcoux/GoldMines.git
npm i
npm run test
- Try to read the results of the tests
Expected behavior
describe
According to the documentation:
describe(name, fn) creates a block that groups together several related tests in one ātest suiteā.
This should start 2 tests suite:
describe('test 1',() => {
test('one space, one mine', () => {
expect(findBestSpot(1, 1, 1, 1, [{"x":0,"y":0}])).toEqual({"coordinates":{"x":0,"y":0},"goldMines":1});
});
});
describe('test 2',() => {
test('one space, no mine', () => {
expect(findBestSpot(1, 1, 1, 1, [])).toEqual({"coordinates":{"x":0,"y":0},"goldMines":0});
});
});
Actual result:
=> Test Suites: 1 failed, 1 total
bail
According to the documentation:
The bail config option can be used here to have Jest stop running tests after the first failure.
Running: npx jest -b
Actual result:
=> Tests: 23 failed, 10 passed, 33 total
How could 23 tests fail if jest did stop at first failure?
each
According to the documentation:
Generate unique test titles by positionally injecting parameters with printf formatting:
So this testās name should be ānameā, but instead, itās name is ā1āā¦
const A = [[1, 2, 3, "name"]];
test.each(A)('%s', (a,b,c) => expect(a+b).toBe(c));
Actual result:
PASS ./index.test.js
ā 1 (5ms)
By the way, ā%4$sā doesnāt work eitherā¦
Link to repl or repo (highly encouraged)
A small repo with a single test file that perfectly illustrate the issue
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i7-5650U CPU @ 2.20GHz
Binaries:
Node: 8.9.2 - ~/.nvm/versions/node/v8.9.2/bin/node
Yarn: 1.12.1 - ~/.yarn/bin/yarn
npm: 6.3.0 - ~/.nvm/versions/node/v8.9.2/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 13
- Comments: 23 (6 by maintainers)
Sorry guys, but I slept on this, and it really bugs me.
When you decide to use an option to stop the tests after the first failure, in what kind of context would it be the expected behavior that it keeps failing all the tests in the current file?
Moreover, you are telling me that with jest, if I want to create 20 tests and I want the tests to stop at the first failure, my only choice is to create 20 test files?!
Every other test system Iāve used means I can add
--bail
and then the output of the failed test is the most recent thing in scroll.Not jest.
Please, please, please, fix this?
With all due respect (and do mean respect), Michal, the ācollaboratorā badge that you and several other people sport here, suggests you are more capable to address this issue (with no need of assuming the offensive). I apologize if I sounded rude, sorry - I wanted to draw attention to this issue.
Apparently it is an issue - it was reported a year ago - there was an argument, yet the OPās reasons seem to outweigh the responses. There is no working
bail
, no way to abruptly stop the tests - if itās the part of the bigger design, maybe it should be shared? Or fixed accordingly?You might find me narrow-minded, but I donāt think that
that I can read there, would normally be interpreted by:
Actually, I think that most people would understand:
Jest will stop running tests after the first failure
šIāll check if Iām able to provide a PR about this if you are willing to change the way bail is working.
@cpojer what do you think about
--bail
stopping at the first test instead of the first test file?@Sharcoux if the docs arenāt clear about this then Iām happy to merge a clarification š
Just got bitten by this as well. Iād say that the current description of
bail
is even more misleading:Bail currently keeps running the remaining tests in a file even when the first one fails i.e. it does not appear to āexit the suite immediatelyā.
Or does it mean that it should exit jest (not the test suite) immediately after a single test suite fails? Either way the language and grammar are rather confusing.
Thanks for your reply.
Iām not sure about the relevance of the
describe
function in this caseā¦ But ok. The doc should really be corrected, though, because it is very confusing.Shouldnāt this be reflected into the doc?
In my use case, I provide students with a project that have already the tests written for them. In this case, if they run
npm run test
they will be flooded by test failures and they will only be able to read the last tests, whereas the tests are written with progressive difficulty. But the one they are interested in are probably the first ones.Fortunately, I finally could work around this by hacking my way through
each
.That is the thing, you canāt. In the end I had to separate the describe blocks into different files.