What is the difference between ‘it’ and ‘test’ in jest?

What is the difference between ‘it’ and ‘test’ in jest?

I have two tests in my test group. One uses it the other one uses test, and they seem to be working very similarly. What is the difference between them?
describe(‘updateAll’, () => {
it(‘no force’, () => {
return updateAll(TableName, [“fileName”], {compandId: “test”})
.then(updatedItems => {
let undefinedCount = 0;
for (let item of updatedItems) {
undefinedCount += item === undefined ? 1 : 0;
}
// console.log(“result”, result);
expect(undefinedCount).toBe(updatedItems.length);
})
});

test(‘force update’, () => {
return updateAll(TableName, [“fileName”], {compandId: “test”}, true)
.then(updatedItems => {
let undefinedCount = 0;
for (let item of updatedItems) {
undefinedCount += item === undefined ? 1 : 0;
}
// console.log(“result”, result);
expect(undefinedCount).toBe(0);
})
});
});

UPDATE:
It seems that test is in the official API of Jest, but it is not.

Solutions/Answers:

Solution 1:

In the docs it says here: it is an alias of test. So they are exactly the same.

Solution 2:

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

Related:  Detecting a system window overlaying an iframe

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);
});

Docs:

Solution 3:

The do the same thing, but their names are different and with that their interaction with the name of the test.

test

What your write:

describe('yourModule', () => {
  test('if it does this thing', () => {}
  test('if it does the other thing', () => {}
})

What you get if something fails:

yourModule > if it does this thing

it

What you write:

describe('yourModule', () => {
  it('should do this thing', () => {}
  it('should do the other thing', () => {}
})

What you get if something fails:

yourModule > should do this thing

So it’s about readability not about functionality. In my opinion, it really has a point when it comes to read the result of a failing test that you haven’t written yourself. It helps to faster understand what the test is about.

Related:  Change button style on press in React Native

Solution 4:

They are the same thing. I am using TypeScript as the programming language, and when I look into the definition file from jest package source code from /@types/jest/index.d.ts, I can see the following codes. Obviously there are lots of different names of ‘test’, you can use any of them.

declare var beforeAll: jest.Lifecycle;
declare var beforeEach: jest.Lifecycle;
declare var afterAll: jest.Lifecycle;
declare var afterEach: jest.Lifecycle;
declare var describe: jest.Describe;
declare var fdescribe: jest.Describe;
declare var xdescribe: jest.Describe;
declare var it: jest.It;
declare var fit: jest.It;
declare var xit: jest.It;
declare var test: jest.It;
declare var xtest: jest.It;