# browser-unit-test

> > A minimal test runner that runs tests directly in the browser

Latest version **0.0.7** (published 2022-09-30) · 0 weekly downloads

## Install

```sh
npm install browser-unit-test
pnpm add browser-unit-test
yarn add browser-unit-test
bun add browser-unit-test
```

Provides the command `browser-unit-test`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2022-09-30 |
| First published | 2022-06-04 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | falkz |

## Links

- npm: https://www.npmjs.com/package/browser-unit-test
- npm.io page: https://npm.io/package/browser-unit-test

## Dependencies (2)

- [ast-source](https://npm.io/package/ast-source.md) ^3.0.0
- [estraverse](https://npm.io/package/estraverse.md) ^5.3.0

## Recent versions

- 0.0.7 (latest) — 2022-09-30
- 0.0.6 — 2022-09-27
- 0.0.5 — 2022-09-27
- 0.0.4 — 2022-09-24
- 0.0.3 — 2022-09-24
- 0.0.2 — 2022-06-24
- 0.0.1 — 2022-06-24
- 0.0.0 — 2022-06-04

## README

> A minimal test runner that runs tests directly in the browser

# Features

- Modern platform features like esm & async / await
- Test with the real DOM & Browser APIs
- First class Typescript support & live reload: The test runner uses [vite](https://vitejs.dev/)!
- [Easy and concise way to write tests](#basics)
  ```js
  export const aTest = () => assert(value !== 0);
  ```
- [](#test-results)

[Motivation behind this test runner](#motivation)

# Getting started

1. Install

```bash
npm i -D vite browser-unit-test
```

2. Create scaffolding

```bash
npx browser-unit-test init
# or: pnpm exec browser-unit-test init
```

3. Run tests

```bash
npx vite test
# or: pnpm exec vite test
```

---

> **Pro tip:** Use browser debugging to see your test results directly in your IDE: [e.g. VSCode browser debugging](https://code.visualstudio.com/docs/nodejs/browser-debugging)

# Basics

## Tests

Tests are just functions that are exported:

```js
export const aTest = () => assert(value !== 0);
```

By default all the files that have a `.test.js` or a `.test.ts` ending in the `/test` folder get executed by the runner.

## Asserts

Are asserts like this `assert(value !== 0)` really a good idea?

- For readability: yes
- For logging: normally no

You normally don't get the context of why the assertion failed when you use this pattern. **But** this library provides a small transform, which prints you the actual values for both sides of the comparison.

# Test results

The test results will be displayed in the browser console, and are grouped by file and function.

# Motivation

If you build code for targeting a web-browser. Why run unit tests in node.js? Because all the API are different and the logging and inspection is so great. Surely not :smile:. That is reason for this library, to define and run unit tests directly in the browser. (Note: there is currently no support for CI. It is only meant to run during development)

---
_Source: https://npm.io/package/browser-unit-test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
