# Unit Test

*noun*

say it: **“YOO-nit test”** **/ˈjuːnɪt tɛst/**

A small piece of code that runs one function with chosen inputs and checks that the answer is what you expected.

## What is **Unit Test** in JavaScript?

**Unit Test** — A small automated check of one focused unit of behavior.

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

## In a sentence

- “I wrote a **unit test** that checks addTip(20) gives back 23, so I'll know right away if I break it.”
- “I ran node --test, and every **unit test** for the ticket booth passed.”
- “A **unit test** caught that formatTime(60) returned "0:60" instead of "1:00".”
- “I wrote a **unit test** that checks two lattes and a muffin total $13.50.”
- “The **unit test** failed, which showed me the discount was taken off twice.”

Level: Freelancer · [More JavaScript terms at this level](https://www.ask-codey.com/glossary?category=javascript&level=4)

Updated: November 9, 2026

## In other subjects

- [Unit Test in C#](https://www.ask-codey.com/glossary/unit-test-c-sharp)
- [Unit Test in Java](https://www.ask-codey.com/glossary/unit-test)
- [Unit Test in Unit Testing](https://www.ask-codey.com/glossary/unit-test-unit-testing)

Source: https://www.ask-codey.com/glossary/unit-test-javascript
