Skip to content
/ htest Public
forked from LeaVerou/htest

Declarative, boilerplate-free unit testing

License

Notifications You must be signed in to change notification settings

oddbird/htest

 
 

Repository files navigation

hTest

Declarative, boilerplate-free unit testing, for everyone.

https://htest.dev

What the hTest? Do we really need another unit testing framework?

hTest is a unit testing framework that focuses on making unit testing as quick and painless as possible. Forget copy-pasting 10 lines of boilerplate to write a single test. TDD is hard enough as it stands — the more friction in writing tests, the fewer are written. hTest aims to eliminate all boilerplate, so you can focus on the tests themselves.

hTest can be used in one of two ways: HTML-first or JS-first:

  • In JS-first mode you write your tests in nested object literals, and you can run them either in Node or in the browser. Tests inherit values they don’t specify from their parents, so you never have to repeat yourself.
    • More suitable for pure JS code.
    • Compatible with CI and other automated test running processes.
    • Code must be compatible with Node to use the Node test runner.
  • In HTML-first mode you write your tests in HTML files and run them only in the browser.
    • More suitable for UI-heavy code.
    • Pass-criteria extends beyond value matching or error catching, and could even be things like what CSS selectors match or what the DOM looks like.
    • Reactive evaluation: if the HTML changes or the user interacts with the UI, relevant tests are re-evaluated.
    • Mock interactions like click or focus with HTML attributes.

You can even mix and match the two modes in the same testsuite! E.g. even a UI-heavy library has many JS-only functions that are better tested via JS-first tests.

It is still a work in progress (soft launched), but stable enough to be used in production. The main things that still need to be done before launch are:

  • Fix CLI output glitches and improve usability (ideal would be an interactive tree that starts off collapsed)
  • Improve documentation
  • Ensure we're not missing essential things (setup/teardown?)

Sample terminal output

hTest in the wild

JS-first testsuites

HTML-first testsuites

Testsuites

Single page tests

About

Declarative, boilerplate-free unit testing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 82.3%
  • CSS 15.5%
  • Nunjucks 2.2%