I have two tests in my test group. One of the tests use it
and the other one uses test
. Both of them seem to be working very similarly. What is the dif
As the jest documentation says, they are the same: it alias
test(name, fn, timeout)
Also under the alias: it(name, fn, timeout)
And describe
is just for when you prefer your tests to be organized into groups:
describe
describe(name, fn)
describe(name, fn)
creates a block that groups together several related tests. For example, if you have a myBeverage object that is supposed to be delicious but not sour, you could test it with:
const myBeverage = {
delicious: true,
sour: false,
};
describe('my beverage', () => {
test('is delicious', () => {
expect(myBeverage.delicious).toBeTruthy();
});
test('is not sour', () => {
expect(myBeverage.sour).toBeFalsy();
});
});
This isn't required - you can write the test blocks directly at the top level. But this can be handy if you prefer your tests to be organized into groups.