Catalog npm
Back to packageRELEASE DETAILS

0.2.0

npm

4.5

Monadic test assertions

functionalhttpmostmostjsreactivexhr
Published12 Feb 2017
Direct dependencies18
Transitive dependenciesNot calculated

README

Current package documentation

4.5

Functional, curried, and monadic Assertions

The functional assertions library you've been missing! Your tests should follow the same practices you put into your codebase. If you prefer functional style APIs and practices in JavaScript or TypeScript your tests likely don't look too much like your applications. This library aims to solve this with functionally-oriented assertions that are lazy and monadic.

Table of Contents

Let me have it!

yarn add 4.5
# or
npm install --save 4.5

API

  • All functions of arity 2 or more are curried.
  • All types are defined below in the Types section.

Assertions

Create assertions that can be verified. Assertions are lazy by default, which means, they don't do anything unless specifically asked to verify themselves.

equals :: a → a → Assertion a

Creates an assertion that, when verified, will check value equality of items, including deep equality of objects or arrays.

is :: a → a → Assertion a

Creates an assertion that, when verified, will check reference equality of items.

pass :: a → Assertion a (Applicative)

Creates an assertion that, when verified, will always succeed with the given value.

This is 4.5's implementation of Applicative often called of or just in many other libraries.

fail :: * → Assertion *

Creates an assertion that, when verified, will always fail with a string representation of the given value.

throws :: (* → *) → Assertion Error

Creates an assertion that verifies a given function throws an error.

Combinators

Combinators are what allow you to compose your assertions and express many aspects of your tests in a declarative and expressive way.

map :: (a → b) → Assertion a → Assertion b (Functor)

Given a function from one value a to another value b and an assertion of a returns a new assertion of b.

ap :: Assertion (a → b) → Assertion a → Assertion b (Apply)

Given an assertion of a function of type a to type b and an assertion of type a returns an assertion of type b

chain :: (a → Assertion b) → Assertion a → Assertion b (Monad)

Given a function from one value a to Assertion b and an assertion of type a, returns an assertion of type b

bimap :: ([char] → [char]) → (a → b) → Assertion a → Assertion b (Bifunctor)

The first parameter is a function mapping one string to another upon unsuccessful verification of the provided assertion.

The second parameter is a function mapping a value a to a value of b upon successful verification of the provided assertion.

The third parameter is an assertion of type a.

Returns an assertion of type b. If the assertion given as the third parameter is unsuccessfully verified it will also fail to be verified. If the assertion given as the third parameter is verified it will also successfully verify.

concat:: Assertion a → Assertion a → Assertion a

Concatenate 2 assertions together. The second assertion passed to concat will not be verified if the first assertion failed.

Interpreters

Interpreters are functions that verify assertions.

assert :: Assertion a → unit

Given an assertion that can be successfully verified as correct, it will return void/undefined. Given an assertion that can not be verified as correct, it will throw an Error. This option is perfect for test frameworks that use thrown errors to signal test status, such as Mocha.

Types

export interface Assertion<T> {
  verify(verification: Verification<T>): void;
}

export interface Verification<T> {
  success(actual: T): any;
  failure(message: string): any;
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 18

Native requirements
18 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@typed/curry
Environment
{
  "local_name": "@typed/curry",
  "alias": false,
  "peer_metadata": null
}
^1.0.1runtime
typed-colors
Environment
{
  "local_name": "typed-colors",
  "alias": false,
  "peer_metadata": null
}
^1.0.0runtime
@motorcycle/tslint
Environment
{
  "local_name": "@motorcycle/tslint",
  "alias": false,
  "peer_metadata": null
}
^1.3.0development
@types/glob-expand
Environment
{
  "local_name": "@types/glob-expand",
  "alias": false,
  "peer_metadata": null
}
^0.0.30development
@types/mocha
Environment
{
  "local_name": "@types/mocha",
  "alias": false,
  "peer_metadata": null
}
^2.2.39development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^7.0.5development
@types/superagent
Environment
{
  "local_name": "@types/superagent",
  "alias": false,
  "peer_metadata": null
}
^2.0.36development
commitizen
Environment
{
  "local_name": "commitizen",
  "alias": false,
  "peer_metadata": null
}
^2.9.5development
conventional-changelog-cli
Environment
{
  "local_name": "conventional-changelog-cli",
  "alias": false,
  "peer_metadata": null
}
^1.2.0development
cz-conventional-changelog
Environment
{
  "local_name": "cz-conventional-changelog",
  "alias": false,
  "peer_metadata": null
}
^1.2.0development
glob-expand
Environment
{
  "local_name": "glob-expand",
  "alias": false,
  "peer_metadata": null
}
^0.2.1development
husky
Environment
{
  "local_name": "husky",
  "alias": false,
  "peer_metadata": null
}
^0.13.1development
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
^3.2.0development
rimraf
Environment
{
  "local_name": "rimraf",
  "alias": false,
  "peer_metadata": null
}
^2.5.4development
ts-node
Environment
{
  "local_name": "ts-node",
  "alias": false,
  "peer_metadata": null
}
^2.1.0development
tslint
Environment
{
  "local_name": "tslint",
  "alias": false,
  "peer_metadata": null
}
^4.4.2development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^2.1.6development
validate-commit-msg
Environment
{
  "local_name": "validate-commit-msg",
  "alias": false,
  "peer_metadata": null
}
^2.11.1development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "ead554580944226378525613b5e5203408755f3b",
  "tarball": "https://registry.npmjs.org/4.5/-/4.5-0.2.0.tgz",
  "integrity": "sha512-slFHCtA6NFD8b4cV6NCHEFFURl8FCTTuvclnG6BYrQaPrfyVCCVNWaaooHj63rB0A87mZHEkadncR8W1ROAk1w==",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIFaGqtdhqESq/u7I98V0pQ0ZnIx4eI29U8wlVXRlfOijAiBkXu0OGqA8bOIuMFNCsxlFrQUvP2w2RvBiPsUXOYA29g=="
    }
  ]
}

Repository

PENDING
tylors/4.5

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:57 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:8640b468653455db3f55eb9f293a5fa98f046ff6d8e6e519639fe89cbeec5ffa

Other collected versions

0.5.017 Feb0.4.017 Feb0.3.017 Feb0.1.012 FebView all collected versions →