forked from MRJUANGAVIRIA/test-jests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9d994aa
Showing
24 changed files
with
9,391 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
coverage/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Es hora de las intantaneas Snapshot 1`] = ` | ||
Object { | ||
"gender": "Male", | ||
"id": 1, | ||
"name": "Rick Sanchez", | ||
"species": "Human", | ||
"status": "Alive", | ||
} | ||
`; | ||
|
||
exports[`Es hora de las intantaneas Tenemos una excepcion dentro del codigo 1`] = ` | ||
Object { | ||
"id": Any<Number>, | ||
"name": "Oscar Barajas Tavares", | ||
} | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { arrayFruits, arrayColors } from '../arrays'; | ||
|
||
describe('Comprobaremos que existe un elemento', () => { | ||
test('¿Tiene una banana?', () => { | ||
expect(arrayFruits()).toContain('banana'); | ||
}); | ||
test('No contiene un Platano', () => { | ||
expect(arrayFruits()).not.toContain('platano'); | ||
}); | ||
test('Comprobar el tamaño de un arreglo', () => { | ||
expect(arrayFruits()).toHaveLength(6); | ||
}); | ||
test('Comprabaremos que existe un color', () => { | ||
expect(arrayColors()).toContain('azul'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getDataFromApi } from '../promise'; | ||
|
||
describe('Probar Async/Await', () => { | ||
test('Realizar una peticion a una api', async () => { | ||
const api = 'https://rickandmortyapi.com/api/character/'; | ||
const getRick = 'https://rickandmortyapi.com/api/character/1' | ||
await getDataFromApi(api).then(data => { | ||
expect(data.results.length).toBeGreaterThan(0); | ||
}); | ||
await getDataFromApi(getRick).then(data => { | ||
expect(data.name).toEqual('Rick Sanchez'); | ||
}); | ||
}); | ||
|
||
test('Realizando una peticion a una api con error', async () => { | ||
const apiError = 'http://httpstat.us/500'; | ||
const peticion = getDataFromApi(apiError); | ||
await expect(peticion).rejects.toEqual(Error('Request failed with status code 500')); | ||
}); | ||
|
||
test('Realizando una peticion a una api con 404', async () => { | ||
const apiError = 'http://httpstat.us/404'; | ||
const peticion = getDataFromApi(apiError); | ||
await expect(peticion).rejects.toEqual(Error('Request failed with status code 404')); | ||
}); | ||
|
||
test('Resuelve un Hola', async () => { | ||
await expect(Promise.resolve('Hola')).resolves.toBe('Hola'); | ||
await expect(Promise.reject('Error')).rejects.toBe('Error'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { callbackHell } from '../callbacks'; | ||
|
||
|
||
describe('Probando un Callback', () => { | ||
test('Callback', done => { | ||
function otherCallback(data) { | ||
expect(data).toBe('Hola Javascripters') | ||
done(); | ||
}; | ||
callbackHell(otherCallback); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
describe('Matchers', () => { | ||
const user = { | ||
name: 'Juan', | ||
lastname: 'Gaviria' | ||
} | ||
|
||
const user2 = { | ||
name: 'David', | ||
lastname: 'Agudelo' | ||
} | ||
|
||
test('Igualdad de elementos', () => { | ||
expect('JUAN').toEqual('JUAN') | ||
}); | ||
|
||
test('Desigualdad de elementos', () => { | ||
expect(user).not.toEqual(user2) | ||
}); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { sumar, multiplicar, restar, dividir } from '../maths.js'; | ||
|
||
describe('calculos', () => { | ||
test('Prueba sumar', () => { | ||
expect(sumar(1, 2)).toBe(3); | ||
}); | ||
|
||
test('Prueba multiplicar', () => { | ||
expect(multiplicar(2, 2)).toBe(4); | ||
}); | ||
|
||
test('Prueba restar', () => { | ||
expect(restar(2, 2)).toBe(0); | ||
}); | ||
|
||
test('Prueba dividir', () => { | ||
expect(dividir(6, 2)).toBe(3); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { numbers } from '../numbers'; | ||
|
||
describe('Comparacion de numeros', () => { | ||
test('Mayor que', () => { | ||
expect(numbers(2,20)).toBeGreaterThan(9); | ||
}); | ||
test('Mayor que o igual', () =>{ | ||
expect(numbers(15,15)).toBeGreaterThanOrEqual(30); | ||
}); | ||
test('Menor que', () => { | ||
expect(numbers(2,2)).toBeLessThan(5); | ||
}); | ||
test('Menor que o igual', () => { | ||
expect(numbers(2,2)).toBeLessThanOrEqual(5); | ||
}); | ||
test('Numeros flotantes', () => { | ||
expect(numbers(0.2,0.2)).toBeCloseTo(0.4); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getDataFromApi } from '../promise'; | ||
|
||
describe('Probando promesas', () => { | ||
test('Realizando peticion a un API', done => { | ||
const api = 'https://rickandmortyapi.com/api/character/'; | ||
getDataFromApi(api).then(data => { | ||
expect(data.results.length).toBeGreaterThan(0); | ||
done(); | ||
}); | ||
}); | ||
|
||
test('Resuelve in Hola!', () => { | ||
return expect(Promise.resolve('Hola')).resolves.toBe('Hola'); | ||
}); | ||
|
||
test('Rechaza con un error', () => { | ||
return expect(Promise.reject('Errror')).rejects.toBe('Errror'); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// despues de cada prueba | ||
afterEach(() => console.log('Despues de cada prueba')); | ||
afterAll(() => console.log('Despues de todas las pruebas')); | ||
|
||
// antes de cada prueba | ||
beforeAll(() => console.log('Antes de todas las pruebas')); | ||
beforeEach(() => console.log('Antes de cada prueba')); | ||
|
||
describe('preparar antes de ejecutar', () => { | ||
test('Es verdadero', () => { | ||
expect(true).toBeTruthy(); | ||
}); | ||
|
||
test('Es Falso', () => { | ||
expect(false).toBeFalsy(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getCharacter } from '../snapshot'; | ||
import rick from '../rick.json'; | ||
|
||
describe('Es hora de las intantaneas', () => { | ||
test('Snapshot', () => { | ||
expect(getCharacter(rick)).toMatchSnapshot(); | ||
}); | ||
|
||
// test('Siempre fallara la instantanea', () => { | ||
// const user = { | ||
// createAt: new Date(), | ||
// id: Math.floor(Math.random() * 20), | ||
// } | ||
// expect(user).toMatchSnapshot(); | ||
// }); | ||
|
||
test('Tenemos una excepcion dentro del codigo', () => { | ||
const user = { | ||
id: Math.floor(Math.random() * 20), | ||
name: "Oscar Barajas Tavares" | ||
} | ||
expect(user).toMatchSnapshot({ | ||
id: expect.any(Number) | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
describe('Comprobar cadenas de texto', () => { | ||
const text = 'un bonito texto'; | ||
test('debe contener el siguiente texto', () => { | ||
expect(text).toMatch(/bonito/); | ||
}); | ||
test('No contiene el siguiente texto', () => { | ||
expect(text).not.toMatch(/es/); | ||
}); | ||
test('comprobar el tamaño de un texto', () => { | ||
expect(text).toHaveLength(15); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { isNull, isTrue } from '../true'; | ||
import { isFalse, isUndefined } from '../true'; | ||
|
||
describe('Probar resultados nulos', () => { | ||
test('null', () => { | ||
expect(isNull()).toBeNull(); | ||
}); | ||
}); | ||
describe('Probar resultados verdaderos', () => { | ||
test('Verdadero', () => { | ||
expect(isTrue()).toBeTruthy(); | ||
}); | ||
}); | ||
describe('Probar resultados falsos', () => { | ||
test('falsos', () => { | ||
expect(isFalse()).toBeFalsy(); | ||
}); | ||
}); | ||
describe('Probar resultados undefined', () => { | ||
test('undefined', () => { | ||
expect(isUndefined()).toBeUndefined(); | ||
}); | ||
}); | ||
describe('Probar resultados no verderos', () => { | ||
test('Falso o verdadero', () => { | ||
expect(isTrue()).not.toBeFalsy(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const fruits = ['banana', 'melon', 'sandia', 'naranja', 'limon', 'pepino']; | ||
const colors = ['azul', 'verde', 'rojo', 'rosa', 'amarillo']; | ||
|
||
export const arrayFruits = () => fruits; | ||
export const arrayColors = () => colors; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
presets: [['@babel/preset-env', {targets: {node: 'current'}}]], | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function callbackHell(callback) { | ||
callback('Hola Javascripters'); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const sumar = (a, b) => { | ||
return a + b; | ||
}; | ||
|
||
export const multiplicar = (a, b) => { | ||
return a * b; | ||
}; | ||
|
||
export const restar = (a, b) => { | ||
return a - b; | ||
}; | ||
|
||
export const dividir = (a, b) => { | ||
return a / b; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const numbers = (a, b) => { | ||
return a + b; | ||
} |
Oops, something went wrong.