Skip to content

Stub

Easy — everyone uses thisTesting

ELI5 — The Vibe Check

A stub is like a cardboard cutout of a function. It stands in for the real thing and always gives you the same canned response. Unlike a mock, you don't check HOW it was called — it just quietly returns whatever you set up.

Real Talk

A stub is a test double that provides predefined responses to method calls. Unlike mocks, stubs don't verify how they were called — they only provide controlled return values. Stubs are used to replace unpredictable dependencies like APIs or clocks.

Show Me The Code

// Stub always returns the same user
const userStub = {
  findById: (id) => ({ id, name: 'Test User', email: 'test@example.com' })
};

const result = renderProfile(userStub, 42);
expect(result).toContain('Test User');

When You'll Hear This

"Stub out the database call so we can test the formatting logic." / "Use a stub when you just need a controlled return value."

Made with passive-aggressive love by manoga.digital. Powered by Claude.