# a-sert

> ☑ functional assertions

Latest version **0.0.11** (published 2020-03-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install a-sert
pnpm add a-sert
yarn add a-sert
bun add a-sert
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2020-03-13 |
| First published | 2020-02-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Richard Tong |
| Maintainers | richytong |
| Keywords | a-sert, a, assert, async, test, testing, functional, fp |

## Links

- npm: https://www.npmjs.com/package/a-sert
- Repository: https://github.com/richytong/a-sert
- Homepage: https://github.com/richytong/a-sert#readme
- Issues: https://github.com/richytong/a-sert/issues
- npm.io page: https://npm.io/package/a-sert

## Dependencies (2)

- [rubico](https://npm.io/package/rubico.md) ^0.1.81
- [deep-equal](https://npm.io/package/deep-equal.md) ^2.0.1

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 0.0.11 (latest) — 2020-03-13
- 0.0.10 — 2020-03-03
- 0.0.9 — 2020-03-03
- 0.0.8 — 2020-03-02
- 0.0.7 — 2020-03-02
- 0.0.6 — 2020-02-28
- 0.0.5 — 2020-02-28
- 0.0.4 — 2020-02-26
- 0.0.3 — 2020-02-26
- 0.0.2 — 2020-02-26
- 0.0.1 — 2020-02-25

## README

# a-sert
☑ functional assertions

## Why?
- I like functional programming
- I never use `assert.equal`
- I hardly test for internal reference equality
- `assert` methods are too long to type

## Methods
`a.eq` - takes values or functions that transform the input  
then checks for strict or deep equality of their computed values

`a.eq.sync` - same as above but all functions must be sync

`a.err` - checks that a provided function throws or rejects  
a provided error

`a.err.sync` - same as above but provided function must be sync

## Examples
Basic usage
```javascript
const a = require('a-sert')

a.eq(1, x => x.a, x => x.b - 1)({ a: 1, b: 2 })
// => ({ a: 1 }, { b: 2 })

a.eq(1, x => x.a)({ a: 2 })
// throws AssertionError('2 !== 1')

a.eq(x => x, { a: 1 })({ a: 1 })
// => ({ a: 1 })

a.eq(x => x, { a: 1 })({ a: 2 })
// throws AssertionError('{"a":1} !deepEqual {"a":2}')

a.err(
  () => { throw new TypeError('hey') },
  new TypeError('hey'),
)('yo')
// => 'yo'

a.err(
  x => x,
  new RangeError('hey'),
)('yo')
// => throws AssertionError('did not throw RangeError: hey')
```

A test in mocha
```javascript
const _ = require('rubico')
const a = require('a-sert')
const connectorDynamo = require('.')

describe('connectorDynamo', () => {
  it('instantiates a DynamoDB client', () => _.flow(
    connectorDynamo,
    a.eq('localhost', _.get('client.endpoint.hostname')),
    a.eq('http:', _.get('client.endpoint.protocol')),
    a.eq(8000, _.get('client.endpoint.port')),
  )({
    endpoint: 'http://localhost:8000',
    credentials: {
      access_key_id: 'hey',
      secret_access_key: 'secret',
    },
    region: 'us-east-1',
  }))
})
```

---
_Source: https://npm.io/package/a-sert · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
