Skip to content

Vitest

Vitest runs automated JavaScript and TypeScript tests and reports which expectations pass or fail.

Visit Vitest

What can Vitest check without opening a browser?

Give one piece of code a known input and compare its answer with what you expected. For example, a workshop priced at 20 with a discount of 5 should return 15. Repeat with no discount so the test covers both choices.

Node.js is the default place Vitest runs. You can use it for logic that needs neither a page nor a network connection.

When do you need a real browser?

A simulated document can help check text and controls. For behavior that depends on the browser itself, Vitest has a separate Browser Mode with browser setup. Use a disposable local test and fictional inputs. A passing code test does not establish that an entire customer journey works.

The runner is MIT-licensed. Keep the test files, runner settings and expected examples with your project. Reports can show the expected and actual values. Store reports only where the team needs them.

How can you write an expectation that catches a bad result?

Use a fictional class total on paper. Do not connect a checkout or use customer data.

  1. Write both inputs
    Write down the base total and the made-up discount.
  2. Mark the expected output
    Mark 15 as the expected total. Compare it with an intentionally wrong output of 20.
  3. Describe the failure
    Record both numbers so the person fixing the rule can see what failed. No code was run.