Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 598
C.Lee Avatar asked Aug 20 '17 03:08

C.Lee


People also ask

What is it and test in Jest?

Jest is an open-source testing framework built on JavaScript, designed majorly to work with React and React Native based web applications. Often, unit tests are not very useful when run on the frontend of any software. This is mostly because unit tests for the front-end require extensive, time-consuming configuration.

What is the use of test in Jest?

It's as simple as the name suggests. We expect something to work as expected and we check if it does. It can be your homework, task or anything which you wanna check for something expected. And in our case, we want our program to work as expected, so we test it.

What are Jest tests?

Jest is a JavaScript testing framework designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable, familiar and feature-rich API that gives you results quickly. Jest is well-documented, requires little configuration and can be extended to match your requirements.

Is Jest enough for testing?

Jest is a JavaScript test runner that lets you access the DOM via jsdom . While jsdom is only an approximation of how the browser works, it is often good enough for testing React components.


1 Answers

The Jest docs state it is an alias of test. So they are exactly the same from a functional point of view. They exist both to enable to make a readable English sentence from your test.

like image 96
musicformellons Avatar answered Sep 27 '22 21:09

musicformellons