Skip to content

Commit 3e18d2f

Browse files
committed
Add expect.it shorthands
1 parent 504d680 commit 3e18d2f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/createTopLevelExpect.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,17 @@ expectPrototype.addAssertion = function (
707707
// Make sure that all flags are defined.
708708
handler.flags = extend({}, defaultValueByFlag, handler.flags);
709709

710+
this[
711+
handler.testDescriptionString.replace(/ [a-z]/g, ($0) =>
712+
$0.charAt(1).toUpperCase()
713+
)
714+
] = (...args) =>
715+
createExpectIt(
716+
this._topLevelExpect,
717+
[[testDescriptionString, ...args]],
718+
this.flags
719+
);
720+
710721
const assertionHandlers = assertions[handler.testDescriptionString];
711722
handler.specificity = calculateAssertionSpecificity(handler);
712723
if (!assertionHandlers) {
@@ -1579,6 +1590,11 @@ expectPrototype.clone = function () {
15791590
const clonedAssertions = {};
15801591
Object.keys(this.assertions).forEach(function (assertion) {
15811592
clonedAssertions[assertion] = [].concat(this.assertions[assertion]);
1593+
// FIXME: We would get this for free if the assertions were recreated in the clone with addAssertion:
1594+
this[assertion.replace(/ [a-z]/g, ($0) => $0.charAt(1).toUpperCase())] = (
1595+
...args
1596+
) =>
1597+
createExpectIt(this._topLevelExpect, [[assertion, ...args]], this.flags);
15821598
}, this);
15831599
const expect = createTopLevelExpect({
15841600
assertions: clonedAssertions,

0 commit comments

Comments
 (0)