Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Apr 25, 2022
1 parent 66eecb3 commit c70d2d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/addAdditionalPromiseMethods.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Context = require('./Context');

function addAdditionalPromiseMethods(promise, expect, subject) {
function addAdditionalPromiseMethods(promise, expect, subject, args) {
promise.and = function (...args) {
function executeAnd() {
if (expect.findTypeOf(args[0]).is('expect.it')) {
Expand Down Expand Up @@ -32,6 +32,11 @@ function addAdditionalPromiseMethods(promise, expect, subject) {
subject
);
} else {
return expect.execute(
shiftedSubject,
methodName.replace(/[A-Z]/g, ($0) => ` ${$0.toLowerCase()}`),
...args
);
return camelCaseMethods[methodName](shiftedSubject)(...args);
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/createTopLevelExpect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,12 @@ expectPrototype._expect = function (context, args, forwardedFlags) {
} else {
result = makePromise.resolve(result);
}
return addAdditionalPromiseMethods(result, this, subject);
return addAdditionalPromiseMethods(
result,
this,
subject,
Array.prototype.slice.call(args, 0, 2)
);
} catch (e) {
if (e && e._isUnexpected) {
let newError = e;
Expand Down
2 changes: 1 addition & 1 deletion test/camelCaseSyntax.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('camel case syntax', () => {
expect([1, 2, 3]).whenPassedAsParametersTo(Math.max).toEqual(3);
});

it('should fail', () => {
it.only('should fail', () => {
expect(() =>
expect([1, 2, 3]).whenPassedAsParametersTo(Math.max).toEqual(2)
).toThrow(
Expand Down

0 comments on commit c70d2d5

Please sign in to comment.