• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tiniest simplest unit testing library for JavaScript

Tiniest JavaScript unit testing library

This is an in-browser JavaScript library I've been using for years. It's so small and simple that it never occured to me to open source it until I saw all the overly complicated alternatives that are out there.

If you're looking for a JavaScript library full of features or install guides that say things like grunt, npm or bower, you've come to the wrong place. Sorry, this probably isn't for you. Move along now.

If you're looking for a quick way to unit-test a JavaScript function/object in a web-page and don't want to get bogged down in frameworks, you've come to the right place. Take a seat... no scratch that, you'll have everything you need in a few seconds so you may as well remain standing.

10 second tutorial

Download tinytest.js and put it somewhere in your web directory.

Let's say you have a function in adder.js:

function add(a, b) {
  return a + b;
}

Create a test page called adder-test.html (you can name it anything). This includes your code under test, tinytest.js and defines your tests:

<script src="tinytest.js"></script>
<script src="adder.js"></script>
<script>
 tests({

   'adds numbers': function() {
     eq(6, add(2, 4));
     eq(6.4, add(2.4, 4));
   },

   'subtracts numbers': function() {
     eq(-2, add(2, -4)); 
   },

 });
</script>

Open the page in your browser. Green is good. Red is bad. If it's red, look in the JavaScript console for messages.

That's it!

Don't believe me? Here's the source and result.

What else?

If your tests fail, you'll get stack traces:

Function reference

// Force a failure
fail(reason);

// Assert expression is truthy (fail with reason)
assert(expression, reason);

// Assert expected == actual
assertEquals(expected, actual)
eq(expected, actual) // Alias for assertEquals

// Assert expected === actual
assertStrictEquals(expected, actual)

Errm that's it. Now stop wasting time - go test that function.

But, but, but. What about feature X?

It probably doesn't have it. If you need that, you'll probably find it in one of the many more sophisticated frameworks out there. A more detailed discussion can be found here.

Projects using TinyTest

Other stuff

I also have TinyTest for C that follows similar principles of simplicity.

Now check out my other GitHub projects and follow @joewalnes on that Twitter thing.

More Repositories

1

websocketd

Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.
Go
17,086
star
2

reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects
JavaScript
4,168
star
3

smoothie

Smoothie Charts: smooooooth JavaScript charts for realtime streaming data
JavaScript
2,242
star
4

filtrex

A simple, safe, JavaScript Filter Expression compiler for end-users
JavaScript
1,042
star
5

web-vmstats

Prettify vmstats in your browser
JavaScript
1,009
star
6

gcode-viewer

A web-based 3D GCode viewer to help understand 3D printer models.
JavaScript
246
star
7

greendots

Write with those green dots on your GitHub profile
Python
184
star
8

tinytest

A tiny unit-testing framework for C
C
170
star
9

jquery-simple-context-menu

A really simple, good looking jQuery context menu
JavaScript
102
star
10

port-sharding

Example of Linux SO_REUSEPORT
Python
90
star
11

go-getter

Like 'go get' but with pinned package versions. A tiny shell script.
Shell
86
star
12

toybrick

OpenSCAD program to generate toy bricks compatible with existing systems
OpenSCAD
85
star
13

node-ldapauth

LDAP authentication library for Node.JS
C++
70
star
14

resisto.rs

No frills resistor color code tool
HTML
67
star
15

webconnect

JavaScript APIs to allow web-apps to connect to hardware devices.
JavaScript
52
star
16

pi-crust

Connect things to your Raspberry Pi
Eagle
47
star
17

idea-community

IntelliJ IDEA Community edition - my hacks
Java
33
star
18

crunchicorn

Simplifying the web toolchain
JavaScript
32
star
19

verifysignature

Sample of standalone portable C to verify Ed25519 public-key signature
C
21
star
20

raspberry-play

Playing with the Raspberry Pi
JavaScript
14
star
21

hackerspace-globe

Mashup: View HackerSpace status on a WebGL Globe
JavaScript
14
star
22

quick2wire-fritzomatic

A tool to quickly generate Fritzing components.
JavaScript
9
star
23

flashprance

A lightweight communication protocol to send data from your computer/phone to an embedded device by flashing the screen
C++
9
star
24

arduino-play

Playing with Arduino and AVR hardware
C
7
star
25

webbit-easyremote

Simple bidirectional JavaServer<->JavaScriptBrowser remoting, based on WebSockets and Webbit
JavaScript
6
star
26

webbit

Webbit Server: Moved....
5
star
27

webbit-asyncio

Event based asynchronous Java IO library - built on libeio
C
5
star
28

msp430-shiftbrite

C / C++ library to allow MSP430 microcontroller to talk to ShiftBrite RGB module
C++
5
star
29

esper-console

Web based Esper console
JavaScript
3
star
30

thor-gui

A web based GUI for Thor
JavaScript
2
star
31

3d-printing

Thingies I've designed for 3D printing
2
star
32

webbit-sitemesh

SiteMesh 3 for Webbit
Java
2
star
33

graphviz2

Joe's modifications to AT&T's GraphViz/Dot
C
2
star
34

c-stuff

C
1
star
35

vim

.vim
Vim Script
1
star
36

pi-plate-clip

Makes the Adafruit's Raspberry Pi Plate just a liiiiittle bit stronger.
1
star
37

openscad-tutorial

A tutorial for OpenSCAD.
1
star
38

test

1
star
39

domain-watcher

Watches a domain name and notifies me when it's status changes
1
star
40

sitemesh-resources

Additional resources to support SiteMesh project.
1
star
41

atx-psu-breakout

Fork of the ATX PSU breakout board from Dangerous Prototypes.
1
star
42

msp430-rgb-color-cycle

A quick cheap circuit for color cycling an RGB LED using an MSP430 microcontroller.
1
star