|
@ -14,7 +14,7 @@ const expectPromise = (pred, statement, options = {}) => a => (...b) => { |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
.catch(e => |
|
|
.catch(e => |
|
|
(options.shouldNotCatch) |
|
|
options.shouldNotCatch |
|
|
? _assertPromise( |
|
|
? _assertPromise( |
|
|
pred(a, ...b), |
|
|
pred(a, ...b), |
|
|
statement(e, ...b) |
|
|
statement(e, ...b) |
|
@ -29,43 +29,43 @@ const expectPromise = (pred, statement, options = {}) => a => (...b) => { |
|
|
); |
|
|
); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const expect = a => { |
|
|
const expect = thing => { |
|
|
|
|
|
|
|
|
return ({ |
|
|
return ({ |
|
|
done : () => Promise.resolve(), |
|
|
done : () => Promise.resolve(), |
|
|
equal : expectPromise( |
|
|
equal : expectPromise( |
|
|
(a, b) => a === b, |
|
|
(a, b) => a === b, |
|
|
(a, b) => `${a} is not equal to ${b}`, |
|
|
(a, b) => `${a} is not equal to ${b}`, |
|
|
)(a), |
|
|
)(thing), |
|
|
deepEqual : expectPromise( |
|
|
deepEqual : expectPromise( |
|
|
(a, b) => isEq(a, b), |
|
|
(a, b) => isEq(a, b), |
|
|
(a, b) => `${stringify(a)} is not deeply equal to ${stringify(b)}`, |
|
|
(a, b) => `${stringify(a)} is not deeply equal to ${stringify(b)}`, |
|
|
)(a), |
|
|
)(thing), |
|
|
isTrue : expectPromise( |
|
|
isTrue : expectPromise( |
|
|
a => a === true, |
|
|
a => a === true, |
|
|
a => `${a} is not true`, |
|
|
a => `${a} is not true`, |
|
|
)(a), |
|
|
)(thing), |
|
|
hasProp : expectPromise( |
|
|
hasProp : expectPromise( |
|
|
(a, b) => b in a, |
|
|
(a, b) => b in a, |
|
|
(a, b) => `Property ${b} does not exist in ${stringify(a)}`, |
|
|
(a, b) => `Property ${b} does not exist in ${stringify(a)}`, |
|
|
)(a), |
|
|
)(thing), |
|
|
hasPair : expectPromise( |
|
|
hasPair : expectPromise( |
|
|
(a, b, c) => a[b] === c, |
|
|
(a, b, c) => a[b] === c, |
|
|
(a, b, c) => `Pair <${b}, ${c}> does not exist in ${stringify(a)}`, |
|
|
(a, b, c) => `Pair <${b}, ${c}> does not exist in ${stringify(a)}`, |
|
|
)(a), |
|
|
)(thing), |
|
|
resolvesTo : expectPromise( |
|
|
resolvesTo : expectPromise( |
|
|
(a, b) => (a && typeof a.then === 'function') |
|
|
(a, b) => (a && typeof a.then === 'function') |
|
|
? a.then(x => x === b ? Promise.resolve() : Promise.reject()) |
|
|
? a.then(x => x === b ? Promise.resolve() : Promise.reject()) |
|
|
: Promise.reject(`${a} was not a Promise`), |
|
|
: Promise.reject(`${a} was not a Promise`), |
|
|
(a, b) => `${a} does not resolve to ${b}`, |
|
|
(a, b) => `${a} does not resolve to ${b}`, |
|
|
)(a), |
|
|
)(thing), |
|
|
isPromise : expectPromise( |
|
|
isPromise : expectPromise( |
|
|
a => (a && typeof a.then === 'function') |
|
|
a => (a && typeof a.then === 'function') |
|
|
? a.then(() => Promise.resolve()).catch(() => Promise.resolve()) |
|
|
? a.then(() => Promise.resolve()).catch(() => Promise.resolve()) |
|
|
: Promise.reject(), |
|
|
: Promise.reject(), |
|
|
a => `${a} is not a Promise`, |
|
|
a => `${a} is not a Promise`, |
|
|
{ shouldNotCatch: true }, |
|
|
{ shouldNotCatch: true }, |
|
|
)(a), |
|
|
)(thing), |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|