expect-predicate
expect-predicate is an extension for expect that lets you test values against arbitrary predicates.
A value "passes" a predicate if the predicate returns a truthy value.
Installation
Using npm:
$ npm install --save-dev expect expect-predicate
Then, use as you would anything else:
// using ES6 modulesexpect // using CommonJS modulesvar expect = var expectPredicate = expect
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.
// check age is 18 or older // 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.
// check age is not under 18 // check that userList is empty