45
A functionally-oriented test runner
45
is the fast and functional test runner that is easy to use and gets out of
your way.
Let me have it!
npm install --save-dev 45
Features
- Does not rely on globals
- Test failure if no assertions are returned
- Lazy, monadic, and curried test assertions via
4.5
- Promise, Observable, and Async/Await support
- Runs all tests in parallel
- ES2015 and TypeScript support out-of-box
Basic Usage
Create a test file
// test/foo.js // ES2015; const test = const otherTest = // commonjsconst describe given it equals = ; exportstest = exportsotherTest =
In your terminal run
./node_modules/.bin/45 test/foo.js# Supports globs ./node_modules/.bin/45 test/*.js # or without parameters # by default it will search for all .test and .spec files in src/ folder # and for all files in test/ and tests/ folders ./node_modules/.bin/45
And you should see:
Tests
When running 45 from the command line, it will look for all test files
it can, collecting all exports, of no particular export name, that adhere
to the Test
interface described in the types section. This means
that 45 can be extended to handle new test types not offered here via 3rd
party libraries.
All 45 Test
s must return objects adhering to the Assertion
interface
described in the Types section. Many assertions are re-exported by this
library from 4.5. Though a number are provided
by default -- 3rd party libraries implementing the Assertion
interface can be used
100% freely.
describe(thing: string, tests: Array<Test>): Test
Allows collecting many Test
s together as a larger whole. All tests are
run in parallel.
;
given(parameters: string, tests: Array<Test>): Test
Just like describe
in that it allows collecting many Test
s together as a
larger whole, but allows for more descriptive test suites. All tests are run in
parallel.
;
it(does: string, testFn: TestFn): Test
Primitive test type which allows providing a callback to actually perform assertions. By default, will timeout at 2000 milliseconds.
;
timeout(ms: number, test: Test): Test
Allows adjusting the amount of time a test can take to complete.
; ;
beforeEach(hook: () => any, tests: Array<Test>): Test
Allow running a hook before a series of tests. This will run the containing array of tests one after another.
; ; ; ;
Assertions (re-exported from 4.5)
- All functions of arity 2 or more are curried.
- All types are defined below in the types section.
equals<A>(expected: A, actual: A): Assertion<A>
Asserts two values expected
and actual
to have value equality.
is<A>(expected: A, actual: A): Assertion<A>
Asserts two values expected
and actual
to have referential equality.
pass<A>(value: A): Assertion<A>
Creates an assertion which always passes with a given value.
fail(message: any): Assertion<void>
Creates an assertion which will always fail with a given message.
throws(fn: () => any): Assertion<Error>
Creates an assertion that tests that a given function throws and error.
Assertion combinators (re-exported from 4.5)
map<A, B>(fn: (a: A) => B, assertion: Assertion<A>): Assertion<B>
Given a function it maps one assertion value to another.
; ;
ap<A, B>(fn: Assertion<(a: A) => B>, value: Assertion<A>): Assertion<B>
Given an assertion containing a function from a
to b
, and an assertion
of a
returns an assertion of type b
.
; ;
chain<A, B>(fn: (a: A) => Assertion<B>, assertion: Assertion<A>): Assertion<B>
Given a function from one value a to Assertion b and an assertion of type a, returns an assertion of type b Useful for making many assertions using the values from the previous assertion.
bimap
Type signature is to long for the header 😄
bimap failure:string, success:B, assertion: Assertion<A>: Assertion<B>;
Similar to map
but also allows adjusting error messages.
Useful for creating your own error messages.
; ;
concat(one: Assertion<A>, two: Assertion<A>): Assertion<A>
Chain together 2 assertions.
; ;
Types
// 45 interfaces ;