Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

454
Views
¿Cuál es la diferencia entre 'it' y 'test' en Jest?

Tengo dos pruebas en mi grupo de prueba. Una de las pruebas it usa y la otra usa test . Ambos parecen estar funcionando de manera muy similar. ¿Cuál es la diferencia entre ellos?

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

Parece que test está en la API oficial de Jest , pero it es así.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Los documentos de Jest afirman it es un alias de test . Entonces son exactamente iguales desde un punto de vista funcional. Ambos existen para permitir hacer una oración en inglés legible a partir de su prueba.

over 4 years ago · Santiago Trujillo Report

0

Hacen lo mismo, pero sus nombres son diferentes y con eso su interacción con el nombre de la prueba.

test

Lo que escribes:

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

Lo que obtienes si algo falla:

 yourModule > if it does this thing

it

Lo que escribes:

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

Lo que obtienes si algo falla:

 yourModule > should do this thing

Por lo tanto, se trata de la legibilidad, no de la funcionalidad.

En mi opinión it realmente tiene sentido cuando se trata de leer el resultado de una prueba reprobatoria que no has escrito tú mismo. Ayuda a entender más rápido de qué se trata la prueba.

Algunos desarrolladores también acortan Should do this thing a Does this thing que es un poco más corto y también se ajusta semánticamente a la notación it .

over 4 years ago · Santiago Trujillo Report

0

Como han aclarado las otras respuestas, hacen lo mismo.

Creo que los dos se ofrecen para permitir 1) pruebas de estilo " RSpec " como:

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

o 2) pruebas de estilo " xUnit " como:

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

Documentación:

  • https://jestjs.io/docs/en/api.html#describename-fn
  • https://jestjs.io/docs/en/api.html#testname-fn-tiempo de espera
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!