What is the difference between 'it' and 'test' in Jest?

后端 未结 7 1984
滥情空心
滥情空心 2021-01-29 20:12

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

7条回答
  •  时光取名叫无心
    2021-01-29 20:52

    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.

提交回复
热议问题