Skip to content

Instantly share code, notes, and snippets.

View CarmeloRicarte's full-sized avatar
馃彔
Working from home

Carmelo Ricarte Rocamora CarmeloRicarte

馃彔
Working from home
View GitHub Profile
@CarmeloRicarte
CarmeloRicarte / useNavigate.mock.ts
Last active January 22, 2025 23:20
useNavigate mock with Vitest
// this is how to mock partial library for mock a method, in this case, useNavigate
const mockedUseNavigate = vi.fn();
vi.mock("react-router-dom", async () => {
const mod = await vi.importActual<typeof import("react-router-dom")>(
"react-router-dom"
);
return {
...mod,
useNavigate: () => mockedUseNavigate,
};
@CarmeloRicarte
CarmeloRicarte / Vitest-TestingLibrary-React-Typescript.md
Last active November 29, 2022 12:52
Vitest-Testing Library React - Typescript
  1. Instalaciones
    yarn add -D vitest jsdom @vitest/ui @testing-library/react @testing-library/jest-dom @vitest/coverage-c8
  2. Configuraciones
    2.1 Crear el archivo setupTests.ts en el root con lo siguiente:
    import "@testing-library/jest-dom";
    import matchers from "@testing-library/jest-dom/matchers";
    import { expect } from "vitest";
    expect.extend(matchers);
    2.2 En el tsconfig.json, insertar lo siguiente dentro de compilerOptions: "types": ["vitest/globals"]\
@CarmeloRicarte
CarmeloRicarte / Vitest-TestingLibrary-React.md
Last active November 28, 2022 15:41
Vitest - Testing Library - React config for Javascript
  1. Instalaciones
    yarn add -D vitest jsdom @vitest/ui @testing-library/react @vitest/coverage-c8
  2. Configuraciones
    2.1 En vite.config.js, a帽adir lo siguiente al defineConfig:
    test: { environment: 'jsdom', globals: true }
    2.2 En package.json, a帽adir lo siguiente dentro de scripts:
    "test": "vitest",
    "test:ui": "vitest --ui",\
@CarmeloRicarte
CarmeloRicarte / vite-testing-config.md
Created November 3, 2022 08:14 — forked from Klerith/vite-testing-config.md
Vite + Jest + React Testing Library - Configuraciones a seguir

Instalaci贸n y configuracion de Jest + React Testing Library

En proyectos de React + Vite

  1. Instalaciones:
yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react 
yarn add --dev @testing-library/react @types/jest jest-environment-jsdom
  1. Opcional: Si usamos Fetch API en el proyecto:
@CarmeloRicarte
CarmeloRicarte / parse-jwt.js
Created August 6, 2019 09:40 — forked from Klerith/parse-jwt.js
Parse - JWT - Obtener Payload y fecha de creaci贸n y expiraci贸n
function parseJwt (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace('-', '+').replace('_', '/');
return JSON.parse(window.atob(base64));
};