Skip to content

Commit

Permalink
Initial config
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJuanGaviriaK committed Jun 1, 2021
0 parents commit 9d994aa
Show file tree
Hide file tree
Showing 24 changed files with 9,391 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
coverage/
18 changes: 18 additions & 0 deletions __test__/__snapshots__/snapshot.test.js.snap
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",
}
`;
16 changes: 16 additions & 0 deletions __test__/arrays.test.js
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');
});
});
31 changes: 31 additions & 0 deletions __test__/async.test.js
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');
});
});
12 changes: 12 additions & 0 deletions __test__/callbacks.test.js
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);
});
});
20 changes: 20 additions & 0 deletions __test__/matchers.test.js
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)
});

});
19 changes: 19 additions & 0 deletions __test__/maths.test.js
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);
});
});
19 changes: 19 additions & 0 deletions __test__/numbers.test.js
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);
});
});
19 changes: 19 additions & 0 deletions __test__/promise.test.js
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');
});
});
17 changes: 17 additions & 0 deletions __test__/setup.test.js
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();
});
});
26 changes: 26 additions & 0 deletions __test__/snapshot.test.js
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)
});
});
});
12 changes: 12 additions & 0 deletions __test__/strings.test.js
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);
});
});
28 changes: 28 additions & 0 deletions __test__/true.test.js
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();
});
});
5 changes: 5 additions & 0 deletions arrays.js
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;
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
};
3 changes: 3 additions & 0 deletions callbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function callbackHell(callback) {
callback('Hola Javascripters');
};
15 changes: 15 additions & 0 deletions maths.js
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;
};
3 changes: 3 additions & 0 deletions numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const numbers = (a, b) => {
return a + b;
}
Loading

0 comments on commit 9d994aa

Please sign in to comment.