Edge Case
ELI5 — The Vibe Check
Edge cases are the weird, extreme, or unexpected inputs that trip up your code. What if someone types 0 for age? What if the username is 1000 characters long? What if they paste emoji into the password field? These are edge cases — the happy path doesn't cover them.
Real Talk
An edge case is an input or situation at the extreme boundaries of expected operating conditions. Edge cases often expose bugs because code logic is typically optimized for normal inputs. Testing edge cases increases confidence in robustness.
Show Me The Code
// Edge cases for a 'divide' function
test('throws when dividing by zero', () => {
expect(() => divide(10, 0)).toThrow('Division by zero');
});
test('handles negative numbers', () => {
expect(divide(-10, 2)).toBe(-5);
});
test('handles very large numbers', () => {
expect(divide(Number.MAX_SAFE_INTEGER, 1)).toBe(Number.MAX_SAFE_INTEGER);
});
When You'll Hear This
"Make sure to test edge cases like empty arrays and null inputs." / "The bug was an edge case — username with a space at the end."
Related Terms
Corner Case
A corner case is like an edge case but even weirder — it's when MULTIPLE unusual things happen at the same time. An edge case is a weird input.
Fuzzing
Fuzzing is throwing completely random, malformed, or garbage inputs at your program to see if it crashes.
Happy Path
The happy path is when everything goes perfectly — the user types the right thing, the API responds correctly, nothing breaks.
Test Case
A test case is one specific scenario you want to check. 'Does the login work with a correct password?' — that's a test case.