javascript - Jest shows only one test suite, even when multiple top-level calls to describe() exist in the test file - Stack Ove

I'm testing my library with jest, and have a file with several describe calls at the first layer,

I'm testing my library with jest, and have a file with several describe calls at the first layer, but when I run "npm test", It reports: "Test Suites: 1 passed, 1 total" "Tests: 26 passed, 26 total"

Why isn't it reporting several test suites?

As far as I can tell, jest's describe function should create its own test suite, but somehow they're all being bined...

From the jest API, "describe(name, fn) creates a block that groups together several related tests in one test suite"

I'm testing my library with jest, and have a file with several describe calls at the first layer, but when I run "npm test", It reports: "Test Suites: 1 passed, 1 total" "Tests: 26 passed, 26 total"

Why isn't it reporting several test suites?

As far as I can tell, jest's describe function should create its own test suite, but somehow they're all being bined...

From the jest API, "describe(name, fn) creates a block that groups together several related tests in one test suite"

Share Improve this question edited Dec 3, 2018 at 10:42 urig 16.9k32 gold badges118 silver badges208 bronze badges asked Dec 1, 2018 at 22:38 Ben ChislettBen Chislett 4476 silver badges12 bronze badges 6
  • It only reports the top level describes in that way I think, the number of files. – jonrsharpe Commented Dec 1, 2018 at 22:41
  • 1 There are multiple top level describes though, shouldn't that be enough? – Ben Chislett Commented Dec 1, 2018 at 22:43
  • Have you tried splitting them between files to see if it makes a difference? Why is the number of suites so important? – jonrsharpe Commented Dec 1, 2018 at 22:46
  • 2 It isn't really, it's just annoying. I want to know if I'm doing something incorrectly – Ben Chislett Commented Dec 1, 2018 at 22:49
  • Did you add at least one line of functional code to those new test suites? Jest skips empty test suites and empty tests, hence - they may disappear from results. – SzybkiSasza Commented Dec 1, 2018 at 23:32
 |  Show 1 more ment

1 Answer 1

Reset to default 7

It seems that Jest does not really count every top-level call to describe() as a single Test Suite. There's even an open issue in Jest's GitHub repo reporting this behavior as a bug.

Indeed, as you described and as this minimal example on repl.it demonstrates, two top-level calls to describe():

const add = require('./add');
describe('add', () => {
  it('should add two numbers', () => {
    expect(add(1, 2)).toBe(3);
  });
});
describe('add again', () => {
  it('should add two numbers', () => {
    expect(add(1, 0)).toBe(1);
  });
});

Are counted as a single Test Suite:

Jest v22.1.2 node v7.4.0 linux/amd64

 PASS  ./add-test.js
  add
    ✓ should add two numbers (5ms)
  add again
    ✓ should add two numbers

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        1.025s

Current Jest documentation appears to misleading when it states:

describe(name, fn) creates a block that groups together several related tests in one "test suite"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742302117a4418220.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信