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

后端 未结 7 2041
滥情空心
滥情空心 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 21:09

    As the other answers have clarified, they do the same thing.

    I believe the two are offered to allow for either 1) "RSpec" style tests like:

    const myBeverage = {
      delicious: true,
      sour: false,
    };
    
    describe('my beverage', () => {
      it('is delicious', () => {
        expect(myBeverage.delicious).toBeTruthy();
      });
    
      it('is not sour', () => {
        expect(myBeverage.sour).toBeFalsy();
      });
    });
    

    or 2) "xUnit" style tests like:

    function sum(a, b) {
      return a + b;
    }
    
    test('sum adds 1 + 2 to equal 3', () => {
      expect(sum(1, 2)).toBe(3);
    });
    

    Documentation:

    • https://jestjs.io/docs/en/api.html#describename-fn
    • https://jestjs.io/docs/en/api.html#testname-fn-timeout

提交回复
热议问题