5.0.7 • Published 9 months ago

@pacote/jest-either v5.0.7

Weekly downloads
243
License
MIT
Repository
github
Last release
9 months ago

@pacote/jest-either

version minified minified + gzip

Additional matchers for Jest making it easier to test Either objects.

Installation

yarn add @pacote/jest-either

Usage

import matchers from '@pacote/jest-either'

expect.extend(matchers)

.toBeEither()

import { left, right } from 'fp-ts/lib/Either'

test('passes when value is an Either', () => {
  expect(left(true)).toBeEither()
  expect(right(true)).toBeEither()
})

test('passes when value is not an Either', () => {
  expect(undefined).not.toBeEither()
})

.toBeRight()

import { left, right } from 'fp-ts/lib/Either'

test('passes when Either is a right', () => {
  const actual = right({ test: 'ok' })
  expect(actual).toBeRight()
})

test('passes when Either is a left', () => {
  const actual = left(Error())
  expect(actual).not.toBeRight()
})

.toBeLeft()

import { left, right } from 'fp-ts/lib/Either'

test('passes when Either is a left', () => {
  const actual = left(Error())
  expect(actual).toBeLeft()
})

test('passes when Either is a right', () => {
  const actual = right({ test: 'ok' })
  expect(actual).not.toBeLeft()
})

.toEqualRight(value)

import { right } from 'fp-ts/lib/Either'

test('passes when right of Either equals a value', () => {
  const actual = right({ test: 'ok' })
  expect(actual).toEqualRight({ test: 'ok' })
})

test('passes when right of Either does not equal a value', () => {
  const actual = right({ test: 'unexpected' })
  expect(actual).not.toEqualRight({ test: 'ok' })
})

.toEqualLeft(value)

import { left } from 'fp-ts/lib/Either'

test('passes when left of Either equals a value', () => {
  const actual = left(Error('message'))
  expect(actual).toEqualLeft(Error('message'))
})

test('passes when left of Either does not equal a value', () => {
  const actual = left(Error('unexpected'))
  expect(actual).not.toEqualLeft(Error('message'))
})

.toMatchRight(object)

import { right } from 'fp-ts/lib/Either'

test('passes when right of Either matches an object', () => {
  const actual = right({ test: 'ok', foo: 'bar' })
  expect(actual).toMatchRight({ test: 'ok' })
})

test('passes when right of Either does not match an object', () => {
  const actual = right({ test: 'unexpected', foo: 'bar' })
  expect(actual).not.toMatchRight({ test: 'ok' })
})

.toMatchLeft(object)

import { left } from 'fp-ts/lib/Either'

test('passes when left of Either matches an object', () => {
  const actual = left({ test: 'ok', foo: 'bar' })
  expect(actual).toMatchLeft({ test: 'ok' })
})

test('passes when left of Either does not match an object', () => {
  const actual = left({ test: 'unexpected', foo: 'bar' })
  expect(actual).not.toMatchLeft({ test: 'ok' })
})

License

MIT © Luís Rodrigues.

5.0.7

9 months ago

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4

1 year ago

5.0.3

2 years ago

5.0.1

2 years ago

5.0.0

3 years ago

4.0.9

3 years ago

4.0.8

3 years ago

4.0.7

3 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

5 years ago