Skip to content

Instantly share code, notes, and snippets.

View ivanbtrujillo's full-sized avatar

Ivanbtrujillo ivanbtrujillo

View GitHub Profile
@ivanbtrujillo
ivanbtrujillo / sum.test.tsx
Created June 6, 2019 17:31
react-testing-library-article-4
import React from "react";
import { render, cleanup, fireEvent } from "@testing-library/react";
import Sum from "./Sum";
describe("Sum", () => {
it('should have two inputs to add the numbers', () => {
const { getByTestId } = render(<Sum />);
const firstInput = getByTestId("value1");
@ivanbtrujillo
ivanbtrujillo / sum.tsx
Created June 6, 2019 17:30
react-testing-library-article-3
import React from "react";
const Sum = () => <div />;
export default Sum;
@ivanbtrujillo
ivanbtrujillo / sum.test.tsx
Created June 6, 2019 17:29
react-testing-library-article-1
import React from "react";
import { render, cleanup, fireEvent } from "@testing-library/react";
import Sum from "./Sum";
describe("Sum", () => {
afterEach(cleanup)
it("should render", () => {
const SumComponent = render(<Sum />);
expect(SumComponent).toBeTruthy();
@ivanbtrujillo
ivanbtrujillo / sum.test.tsx
Last active June 6, 2019 17:28
react-testing-library-article-1
import Sum from './Sum';
describe('Sum', () => {
it('should render', () => (
));
it('should have two inputs to add the numbers', () => (
));
it('should have a button to fire the sum action', () => (
));
it('should have text to show the result', () => (
));
@ivanbtrujillo
ivanbtrujillo / performance-test.js
Last active August 19, 2018 17:13
Performance test of a given function
var perf = function(testName, fn) {
var startTime = new Date().getTime();
fn();
var endTime = new Date().getTime();
console.log(testName + ": " + (endTime - startTime) + "ms");
}
@ivanbtrujillo
ivanbtrujillo / Debugging-react-native-aplication.js
Created May 3, 2018 08:39
Debugging react native aplication - Medium
import React from "react";
import { StyleSheet, Text, View, Button } from "react-native";
export default class App extends React.Component {
state = {
texto: ""
};
saludar = () => this.setState({ texto: "Hola, ¿cómo estás?" });
despedirse = () => this.setState({ texto: "¡Nos vemos!" });
@ivanbtrujillo
ivanbtrujillo / index.html
Created February 9, 2018 15:36
Render Props VS HOC
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Compare HOC and Render Props</title>
</head>
@ivanbtrujillo
ivanbtrujillo / higher-order-functions.js
Created January 29, 2018 14:13
Higher Order Functions
// Las Higher Order Functions nos permiten reutilizar código en Javascript
/*
Partiendo de este ejemplo, tenemos dos funciones en las cuales en una reemplazamos el saludo coloquial por uno mas
formal, y por otro lado lo mismo pero a la hora de despedinos.
*/
var saludoFormal = function(texto) {
return texto.replace(/Hola/ig, "Buenos días");
@ivanbtrujillo
ivanbtrujillo / prettier-eslint.md
Last active January 23, 2018 10:42
Prettier + ESLint en VSCode

En este Gist explico como configurar prettier y eslint en VSCode para que prettier use las reglas de nuestro .eslintrc.json y formatee nuestro codigo en base a esas reglas.

Dependencias

Instalar como dev-dependencies estas dependencias o versiones superiores:

"prettier": "^1.10.2", "prettier-eslint": "^8.8.1"

// ###################################################################
// Arrow function
function sumar(num1, num2) {
return num1 + num2;
}
const sumar = (num1, num2) => num1 + num2;