3

I have found that expect() works within describe(). So the function test() is not necessary, if I see it right. Do I see it right?

In other words, is it enough to write that:

const sum = require('./sum'); describe('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); }); 

Or does that bring advantages:

 const sum = require('./sum'); describe('test sum', () => { test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); }); }); 
2
  • Try a failing test and see where it gets you. A single test isn't a good example because you can just use test (or it) without describe. Commented Oct 16, 2021 at 21:38
  • Does this answer your question? What is the difference between describe and it in Jest? Commented Oct 16, 2021 at 21:41

1 Answer 1

4

describe(name, fn) creates a block that groups together several related tests.

Detail: https://jestjs.io/docs/api#describename-fn

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. But I want to know, if it is fine, to use my fist example without the test()-methode, because it works - it also show failing tests.
@astridx I never try this before and I wouldn't do this. If you only want one layer, use test instead of describe. I think the test report might get wrong if you use your first example

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.