JSPM

fp-ts-jest-matchers

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q58616F
  • License MIT

Jest matchers to nicely test code using fp-ts

Package Exports

  • fp-ts-jest-matchers

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fp-ts-jest-matchers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Jest Matchers for fp-ts

Build and test

This library provides Jest matchers to nicely test code based on fp-ts. Currently it provides matchers for Option and Either.

Installation

First add the dependency to your project:

yarn add --dev fp-ts-jest-matchers

Then make sure this package is loaded by Jest. If you have a file setupTests.ts, you can include it there:

import 'fp-ts-jest-matchers'

If not, you may need to add this to your Jest config:

"jest": {
  "setupFilesAfterEnv": ["fp-ts-jest-matchers"]
}

Usage

After installation, you can now write assertions like these in your test:

import * as O from 'fp-ts/lib/Option'
import * as E from 'fp-ts/lib/Either'
import * as A from 'fp-ts/lib/Array'

it('can test fp-ts options', () => {
    // Expect an option to be 'none':
    expect(O.none.toBeNone()

    // Expect an option to be 'some' with any value:
    expect(O.some('value')).toBeSome()

    // Expect an option to be 'some' with a specific value:
    expect(O.some('value')).toBeSome('value')

    // Use custom Eq for testing the value:
    expect(O.some(['a', 'b'])).toBeSome(['a', 'b'], A.getEq(eqString))
})

it('can test fp-ts eithers', () => {
    // Expect an either to be a left:
    expect(E.left('left value')).toBeLeft()

    // Expect an either to be a left with a specific value:
    expect(E.left('left value')).toBeLeft('left value')

    // Use custom Eq for testing the value:
    expect(E.left(['a', 'b'])).toBeLeft(['a', 'b'], A.getEq(eqString))

    // Expect an either to be a right:
    expect(E.right('right value')).toBeRight()

    // Expect an either to be a right with a specific value:
    expect(E.right('right value')).toBeRight('right value')

    // Use custom Eq for testing the value:
    expect(E.right(['a', 'b'])).toBeRight(['a', 'b'], A.getEq(eqString))
})