graph LR;
Code --> Party;
Party --> Sleep;
Sleep -- Repeat --> Code;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test-5.js | |
const { suma, resta } = require( './funcionesMatematicas' ) | |
test( 'Suma 2 números positivos correctamente', () => { | |
const resultado = suma( 2, 3 ) | |
const esperado = 5 | |
expect( resultado ).toBe( esperado ) | |
} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// funcionesTesting.js | |
// - | |
const esperoQue = ( dato ) => { | |
return { | |
seaIgualQue: ( esperado ) => { | |
if ( dato !== esperado ) { | |
throw new Error( `${ dato } es distinto que ${ esperado }` ) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test-3.js | |
const { suma, resta } = require( './funcionesMatematicas' ) | |
const { esperoQue } = require( './funcionesTesting' ) | |
let resultado, esperado | |
resultado = suma( 2, 3 ) | |
esperado = 5 | |
esperoQue( resultado ).seaIgualQue( esperado ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// funcionesTesting.js | |
const esperoQue = ( dato ) => { | |
return { | |
seaIgualQue: ( esperado ) => { | |
if ( dato !== esperado ) { | |
throw new Error( `${ dato } es distinto que ${ esperado }` ) | |
} | |
// También podríamos usar 👇 | |
// return assert.strictEqual( dato, esperado ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node test-2.js | |
assert.js:89 | |
throw new AssertionError(obj); | |
^ | |
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: | |
-1 !== 5 | |
at Object.<anonymous> (/Users/j.baumann.aguilar/Code/javascript-testing/test-2.js:13:8) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test-2.js | |
// https://nodejs.org/api/assert.html#assert_assert | |
const assert = require( 'assert' ) | |
const { suma, resta } = require( './funcionesMatematicas' ) | |
let resultado, esperado | |
resultado = suma( 2, 3 ) | |
esperado = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test-1.js | |
const { suma, resta } = require( './funcionesMatematicas' ) | |
let resultado, esperado | |
// Probar suma ( 2 + 3 ) | |
resultado = suma( 2, 3 ) | |
esperado = 5 | |
if ( resultado !== esperado ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* test-0.js | |
* | |
* El ejemplo más básico de un test en javascript. En este caso, falla. | |
*/ | |
const resultado = 1 | |
const esperado = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Funciones que vamos a testear | |
const suma = ( num1, num2 ) => num1 + num2 | |
const resta = ( num1, num2 ) => num1 - num2 | |
module.exports = { suma, resta } |
NewerOlder