Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erikras/expect-predicate
An extension for expect that lets you test values against arbitrary predicates
https://github.com/erikras/expect-predicate
Last synced: about 1 month ago
JSON representation
An extension for expect that lets you test values against arbitrary predicates
- Host: GitHub
- URL: https://github.com/erikras/expect-predicate
- Owner: erikras
- License: mit
- Created: 2016-04-29T08:58:54.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-04-29T09:12:39.000Z (over 8 years ago)
- Last Synced: 2024-09-21T10:27:18.160Z (about 2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# expect-predicate
---
[![NPM Version](https://img.shields.io/npm/v/expect-predicate.svg?style=flat-square)](https://www.npmjs.com/package/expect-predicate)
[![NPM Downloads](https://img.shields.io/npm/dm/expect-predicate.svg?style=flat-square)](https://www.npmjs.com/package/expect-predicate)
[![Build Status](https://img.shields.io/travis/erikras/expect-predicate/master.svg?style=flat-square)](https://travis-ci.org/erikras/expect-predicate)
[![codecov.io](https://codecov.io/github/erikras/expect-predicate/coverage.svg?branch=master)](https://codecov.io/github/erikras/expect-predicate?branch=master)[expect-predicate](https://github.com/erikras/expect-predicate) is an extension for
[expect](https://github.com/mjackson/expect) that lets you test values against arbitrary
predicates.**A value "passes" a predicate if the predicate returns a truthy value.**
---
## Installation
Using [npm](https://www.npmjs.org/):
```bash
$ npm install --save-dev expect expect-predicate
```Then, use as you would anything else:
```js
// using ES6 modules
import expect from 'expect'
import expectPredicate from 'expect-predicate'
expect.extend(expectPredicate)// using CommonJS modules
var expect = require('expect')
var expectPredicate = require('expect-predicate')
expect.extend(expectPredicate)
```## Assertions
### toPass
> `expect(value).toPass(predicate, [message])`
Asserts the given value passes the given predicate. If you provide a message, it will be used
when reporting the failure.```js
expect(age).toPass(n => n >= 18) // check age is 18 or older
expect(userList).toPass(array => array.length) // check that userList is not empty
```### toNotPass
> `expect(value).toNotPass(predicate, [message])`
Asserts the given value does NOT pass the given predicate. If you provide a message, it will be
used when reporting the failure.```js
expect(age).toNotPass(n => n < 18) // check age is not under 18
expect(userList).toNotPass(array => array.length) // check that userList is empty
```