Tiny, but fully loaded test-runner.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
976 B

const Promise = require('bluebird');
const { liftPromise } = require('../util');
const _assertPromise = require('./assertPromise');
7 years ago
const expectPromise = (pred, statement, options = {}) =>
toTest =>
(...testValues) =>
liftPromise(
7 years ago
resolvedValue => _assertPromise(
pred(toTest, ...testValues),
[ statement, resolvedValue, ...testValues ],
7 years ago
),
7 years ago
toTest,
)
7 years ago
.catch(rejectedValue =>
options.shouldCatch
7 years ago
? _assertPromise(
pred(toTest, ...testValues),
[ statement, rejectedValue, ...testValues ],
)
7 years ago
: Promise.reject(rejectedValue)
);
const library = require('./assertionsLibrary');
const expects = Object.keys(library).reduce((acc, e) => {
const [ pred, statement, options ] = library[e];
acc[e] = expectPromise(
pred,
statement,
options,
);
return acc;
}, {});
const expect = thing =>
new Proxy({}, {
get: function (obj, prop) {
return expects[prop](thing);
},
});
module.exports = expect;