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
import React from "react"; | |
import { render, cleanup, fireEvent } from "@testing-library/react"; | |
import Sum from "./Sum"; | |
import "jest-dom/extend-expect"; | |
describe("Sum", () => { | |
it('should sum value1 and value2 and show the result', () => { | |
const { getByTestId } = render(<Sum />); | |
const firstInput= getByTestId("value1"); |
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
import React from "react"; | |
const Sum = () => ( | |
<div> | |
<input data-testid="value1" /> | |
<input data-testid="value2" /> | |
</div> | |
); | |
export default Sum; |
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
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"); |
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
import React from "react"; | |
const Sum = () => <div />; | |
export default Sum; |
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
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(); |
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
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', () => ( | |
)); |
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
// ################################################################### | |
// Arrow function | |
function sumar(num1, num2) { | |
return num1 + num2; | |
} | |
const sumar = (num1, num2) => num1 + num2; |
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
var perf = function(testName, fn) { | |
var startTime = new Date().getTime(); | |
fn(); | |
var endTime = new Date().getTime(); | |
console.log(testName + ": " + (endTime - startTime) + "ms"); | |
} |
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
<!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> |
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
// 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"); |