- Instalaciones:
yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react
yarn add --dev @testing-library/react @types/jest jest-environment-jsdom
- Opcional: Si usamos Fetch API en el proyecto:
function parseJwt (token) { | |
var base64Url = token.split('.')[1]; | |
var base64 = base64Url.replace('-', '+').replace('_', '/'); | |
return JSON.parse(window.atob(base64)); | |
}; |
yarn add -D vitest jsdom @vitest/ui @testing-library/react @vitest/coverage-c8
test: { environment: 'jsdom', globals: true }
yarn add -D vitest jsdom @vitest/ui @testing-library/react @testing-library/jest-dom @vitest/coverage-c8
import "@testing-library/jest-dom";
import matchers from "@testing-library/jest-dom/matchers";
import { expect } from "vitest";
expect.extend(matchers);
"types": ["vitest/globals"]
\import { createSlice } from "@reduxjs/toolkit"; | |
import type { PayloadAction } from "@reduxjs/toolkit"; | |
export interface CounterState { | |
counter: number; | |
} | |
const initialState: CounterState = { | |
counter: 0, | |
}; |
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; | |
export const todosApi = createApi({ | |
reducerPath: "todos", | |
baseQuery: fetchBaseQuery({ | |
baseUrl: "https://jsonplaceholder.typicode.com", | |
}), | |
endpoints: (builder) => ({ | |
getTodos: builder.query({ | |
query: () => "/todos", |
import { useState, ChangeEvent, useEffect, useMemo } from "react"; | |
export const useForm = <T extends Object>( | |
initialForm: T, | |
formValidations: { | |
[key: string]: [(value: string) => boolean, string]; | |
} = {} | |
) => { | |
const [formState, setFormState] = useState(initialForm); | |
const [formValidation, setFormValidation] = useState( |
export const getEnvironments = () => {
import.meta.env;
return {
...import.meta.env,
};
import { render, RenderOptions } from '@testing-library/react'; | |
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import { store } from '../../store'; | |
const Providers: React.FC = ({ children }) => { | |
return ( | |
<Provider store={store}> | |
{children} | |
</Provider> |