Describe, bail and each don't work as written in the doc
See original GitHub issueš 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:21 (5 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?!
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?