From c70d2d521f71cbe972befc2b627783526ef78d57 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sun, 20 Feb 2022 23:50:52 +0100 Subject: [PATCH] WIP --- lib/addAdditionalPromiseMethods.js | 7 ++++++- lib/createTopLevelExpect.js | 7 ++++++- test/camelCaseSyntax.spec.js | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/addAdditionalPromiseMethods.js b/lib/addAdditionalPromiseMethods.js index 9d9eb6234..ebf74a9cc 100644 --- a/lib/addAdditionalPromiseMethods.js +++ b/lib/addAdditionalPromiseMethods.js @@ -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')) { @@ -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); } } diff --git a/lib/createTopLevelExpect.js b/lib/createTopLevelExpect.js index fd4b36306..d065f58c9 100644 --- a/lib/createTopLevelExpect.js +++ b/lib/createTopLevelExpect.js @@ -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; diff --git a/test/camelCaseSyntax.spec.js b/test/camelCaseSyntax.spec.js index 29d971486..86b665c70 100644 --- a/test/camelCaseSyntax.spec.js +++ b/test/camelCaseSyntax.spec.js @@ -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(