Skip to content

Instantly share code, notes, and snippets.

@bengrunfeld
bengrunfeld / uuid-generator.js
Created May 19, 2021 14:23
UUID Generator based on random numbers
() => ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,a=>(a^Math.random()*16>>a/4).toString(16))
@bengrunfeld
bengrunfeld / rtl-findBy.ts
Created May 11, 2021 12:29
React Testing Library - findBy
import { render, screen } from '@testing-library/react'
import { App } from './App'
test('Render the App component', () => {
render(<App />)
expect(screen.queryByText('Log In')).toBeNull()
expect(screen.findByText('Log In')).toBeInTheDocument()
})
@bengrunfeld
bengrunfeld / rtl-async-component.tsx
Created May 11, 2021 12:19
React Testing Library - Async Component
const App = () => {
const [loggedIn, setLoggedIn] = useState(false)
useEffect(() => {
setTimeout(() => setLoggedIn(true), 1000)
}, [])
return (
<button>{loggedIn ? "Log Out" : "Log In"}</button>
)
@bengrunfeld
bengrunfeld / rtl-queryBy.ts
Created May 11, 2021 12:12
React Testing Library - queryBy
import { render, screen } from '@testing-library/react'
import { App } from './App'
test('Render the App component', () => {
render(<App />)
expect(screen.queryByText('Missing Element')).toBeNull()
})
@bengrunfeld
bengrunfeld / rtl-getByRole.ts
Created May 11, 2021 11:53
React Testing Library - getByRole
import { render, screen } from '@testing-library/react'
import { App } from './App'
test('Render the App component', () => {
render(<App />)
expect(screen.getByRole('button')).toBeInTheDocument()
})
@bengrunfeld
bengrunfeld / rtl-getByText.ts
Last active May 11, 2021 11:41
React Testing Library - getByText
import { render, screen } from '@testing-library/react'
import { App } from './App'
test("Render the App component", () => {
render(<App />)
expect(screen.getByText("Give me cookies!")).toBeInTheDocument()
})
@bengrunfeld
bengrunfeld / rtl-basic-component.tsx
Last active May 11, 2021 11:51
React Testing Library - Basic Component
const App = () => <button>Give me cookies!</button>
export default App
@bengrunfeld
bengrunfeld / rtl-2.ts
Created May 11, 2021 11:21
React Testing Library - 2
import { render, screen } from '@testing-library/react'
import { App } from './App'
test("Render the App component", () => {
render(<App />)
screen.debug()
})
@bengrunfeld
bengrunfeld / rtl-1.ts
Last active May 11, 2021 11:20
React Testing Library - 1
import { render } from '@testing-library/react'
import { App } from './App'
test("Render the App component", () => {
render(<App />)
})
@bengrunfeld
bengrunfeld / example-demo-binance-api-call.sh
Created April 12, 2021 12:37
Example Binance REST API Request using Curl
curl --request GET 'https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=15m'