# Mock Function

A test function that records calls and can return controlled values.

## What is **Mock Function** in JavaScript?

**Mock Function** — A test function that records calls and can return controlled values.

```javascript
test("totals an order", () => {
    expect(total(3, 4)).toBe(12);
});
```

Level: Freelancer · [More JavaScript terms at this level](https://www.ask-codey.com/glossary/subjects/javascript/freelancer)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/mock-function
