What Happens When You Type a URL and Press Enter
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →Write a failing test, make it pass, clean up. TDD sounds slow but often makes you faster. How the red-green-refactor loop works in practice, where it shines, and where it doesn't fit.
Test-driven development (TDD) has a reputation problem. Some people treat it as a religion; others dismiss it as a slow academic exercise. The reality is more useful: TDD is a tool that works brilliantly for certain kinds of code and adds little for others. Here's how to use it practically.
Then repeat with the next small piece of behaviour.
Watching the test fail first matters. It proves the test can actually detect the problem. A test that has never failed might be testing nothing.
Say we need a function that builds a URL-friendly slug from a title.
Red. Start with the simplest case:
import { slugify } from './slugify'
test('lowercases and joins words with hyphens', () => {
expect(slugify('Hello World')).toBe('hello-world')
})
It fails because slugify doesn't exist yet.
Green. The simplest thing that works:
export function slugify(text) {
return text.toLowerCase().split(' ').join('-')
}
Next red. Add a case that breaks it:
test('removes punctuation and extra spaces', () => {
expect(slugify(' Hello, World! ')).toBe('hello-world')
})
Green again:
export function slugify(text) {
return text
.toLowerCase()
.trim()
.replace(/[^a-z0-9\s-]/g, '')
.replace(/[\s-]+/g, '-')
.replace(/^-|-$/g, '')
}
Refactor if needed, and keep going with edge cases: empty strings, accented characters, numbers. Each test documents one rule about how slugs work. (Regex basics, for the curious.)
Being pragmatic about this is fine. TDD is a technique, not a moral test.
If you take just one thing from TDD, take this: when you fix a bug, write a failing test for it first. It proves you understand the bug, proves the fix works and guarantees it stays fixed. It's the highest-value test you can write. (Debugging systematically.)
A practice where you write a failing test for the next small piece of behaviour, write just enough code to pass it, then refactor, repeating in short cycles.
It can feel slower at first, but it often speeds things up overall by catching mistakes immediately, reducing debugging time and making refactoring safe.
No. It works best for logic with clear inputs and outputs and for bug fixes. Exploratory work, visual design and simple glue code are often better served by other testing approaches.
DNS lookups, TCP and TLS handshakes, HTTP requests, servers, and the browser's rendering pipeline. The whole journey of a web page, explained so it finally clicks.
Read →There are dozens of HTTP status codes, but about fifteen cover nearly everything. What each one means, when to return it, and the mix-ups (401 vs 403, 301 vs 302) that confuse everyone.
Read →A, AAAA, CNAME, MX, TXT and NS records in plain English, why DNS changes seem slow, and the troubleshooting commands that tell you what is really going on.
Read →