Skip to content

Instantly share code, notes, and snippets.

View claudiainbytes's full-sized avatar

Claudia Estupiñán Forero claudiainbytes

View GitHub Profile
@claudiainbytes
claudiainbytes / gist:e8d690600b57977c6ae26bd627bb0156
Created February 11, 2026 18:45
Testing con Context/State Management
// Context
const CartContext = createContext(null)
export const CartProvider = ({ children }) => {
const [items, setItems] = useState([])
const addItem = (item) => setItems([...items, item])
const removeItem = (id) => setItems(items.filter(i => i.id !== id))
return (
@claudiainbytes
claudiainbytes / gist:325e68ed0c804242ba1892760bc98bb4
Created February 11, 2026 18:44
1. Testing APIs y datos asincronos: Mock Service Worker (MSW)
// mocks/handlers.ts
import { http, HttpResponse } from 'msw'
export const handlers = [
http.get('/api/products', () => {
return HttpResponse.json([
{ id: 1, name: 'Product 1', price: 100 },
{ id: 2, name: 'Product 2', price: 200 },
])
}),
@claudiainbytes
claudiainbytes / gist:9aba29a29205732decd597440888acfd
Created February 11, 2026 17:14
1. Testing de Flujos de Usuario Completos
// Componente completo con múltiples interacciones
describe('Shopping Cart Flow', () => {
it('permite agregar, incrementar y eliminar productos', async () => {
const user = userEvent.setup()
render(<ShoppingApp />)
// Usuario agrega producto
const addButton = screen.getByRole('button', { name: /add to cart/i })
await user.click(addButton)
@claudiainbytes
claudiainbytes / gist:3f488e156fcd300f96befd777a865084
Created February 11, 2026 17:03
3. Unit Testing. Utils functions format currency and truncate text
// utils/formatters.ts
export const formatCurrency = (amount: number, locale = 'en-US') => {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: 'USD',
}).format(amount)
}
export const truncateText = (text: string, maxLength: number) => {
if (text.length <= maxLength) return text
@claudiainbytes
claudiainbytes / gist:b0231bac7e8ea9be49a94f5ee7ec87fe
Last active February 11, 2026 17:02
2. Unit Testing. Hooks: useCounter
// Hook
export const useCounter = (initialValue = 0) => {
const [count, setCount] = useState(initialValue)
const increment = () => setCount(c => c + 1)
const decrement = () => setCount(c => c - 1)
const reset = () => setCount(initialValue)
return { count, increment, decrement, reset }
}
@claudiainbytes
claudiainbytes / gist:f8253595137cf149af992d1b1623bdbc
Created February 11, 2026 16:32
1. Unit Testing. Componentes puros: Button
// Component
interface ButtonProps {
variant: 'primary' | 'secondary'
disabled?: boolean
onClick: () => void
children: React.ReactNode
}
export const Button = ({ variant, disabled, onClick, children }: ButtonProps) => (
<button
@claudiainbytes
claudiainbytes / index.md
Created September 7, 2021 22:46 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@claudiainbytes
claudiainbytes / eu_cookie_banner.js
Created October 22, 2020 23:47 — forked from bavington/eu_cookie_banner.js
Simple EU Cookie Law Banner JavaScript
// Cookie for current question
function create_cookie(name, value, days2expire, path) {
var date = new Date();
date.setTime(date.getTime() + (days2expire * 24 * 60 * 60 * 1000));
var expires = date.toUTCString();
document.cookie = name + '=' + value + ';' + 'expires=' + expires + ';' + 'path=' + path + ';';
}
function retrieve_cookie(name) {
var cookie_value = "",
current_cookie = "",
@claudiainbytes
claudiainbytes / Cors.php
Created March 29, 2019 21:30 — forked from drewjoh/Cors.php
Laravel CORS Middleware
<?php // /app/Http/Middleware/Cors.php
namespace App\Http\Middleware;
use Closure;
class Cors {
public function handle($request, Closure $next)
{
return $next($request)