From 4ef1622d028b25fad2cdb0ee604931382dd47e41 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Tue, 31 May 2022 00:08:28 +0200 Subject: [PATCH] simplify --- lib/createTopLevelExpect.js | 40 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/lib/createTopLevelExpect.js b/lib/createTopLevelExpect.js index 8b09a7dc4..16dc88299 100644 --- a/lib/createTopLevelExpect.js +++ b/lib/createTopLevelExpect.js @@ -1322,20 +1322,16 @@ expectPrototype.setErrorMessage = function (err) { expectPrototype.addAdditionalPromiseMethods = function ( promise, - expect, subject, - args, - wrappedExpect ) { + const stack = new Error('hey').stack; + const wrappedExpect = this; + const expect = this._topLevelExpect; // const expect = this; promise.and = function (...args) { function executeAnd() { if (expect.findTypeOf(args[0]).is('expect.it')) { - return expect.addAdditionalPromiseMethods( - args[0](subject), - expect, - subject - ); + return expect.addAdditionalPromiseMethods(args[0](subject), subject); } else { return expect(subject, ...args); } @@ -1344,11 +1340,7 @@ expectPrototype.addAdditionalPromiseMethods = function ( if (this.isFulfilled()) { return executeAnd(); } else { - return expect.addAdditionalPromiseMethods( - this.then(executeAnd), - expect, - subject - ); + return expect.addAdditionalPromiseMethods(this.then(executeAnd), subject); } }; @@ -1359,14 +1351,13 @@ expectPrototype.addAdditionalPromiseMethods = function ( if (expect.findTypeOf(args[0]).is('expect.it')) { return expect.addAdditionalPromiseMethods( args[0](shiftedSubject), - expect, subject ); } else { - if (wrappedExpect) { + if (wrappedExpect !== expect) { return wrappedExpect.shifty( shiftedSubject, - wrappedExpect.args || [], + wrappedExpect.args, [ methodName.replace(/[A-Z]/g, ($0) => ` ${$0.toLowerCase()}`), ...args, @@ -1389,11 +1380,7 @@ expectPrototype.addAdditionalPromiseMethods = function ( if (this.isFulfilled()) { return execute(this.value()); } else { - return expect.addAdditionalPromiseMethods( - this.then(execute), - expect, - subject - ); + return expect.addAdditionalPromiseMethods(this.then(execute), subject); } }; @@ -1403,7 +1390,6 @@ expectPrototype.addAdditionalPromiseMethods = function ( if (expect.findTypeOf(args[0]).is('expect.it')) { return expect.addAdditionalPromiseMethods( args[0](subject), - expect, subject ); } else { @@ -1416,7 +1402,6 @@ expectPrototype.addAdditionalPromiseMethods = function ( } else { return expect.addAdditionalPromiseMethods( this.then(execute), - expect, subject ); } @@ -1441,9 +1426,8 @@ expectPrototype._createWrappedExpect = function ( if (arguments.length === 0) { throw new Error('The expect function requires at least one parameter.'); } else if (arguments.length === 1) { - return wrappedExpect.addAdditionalPromiseMethods( + return parentExpect.addAdditionalPromiseMethods( makePromise.resolve(subject), - wrappedExpect, subject ); } else if (typeof testDescriptionString === 'function') { @@ -1597,13 +1581,9 @@ expectPrototype._executeExpect = function ( } else { result = makePromise.resolve(result); } - // Her mangler vi wrappedExpect? return wrappedExpect.addAdditionalPromiseMethods( result, - this, subject, - Array.prototype.slice.call(args, 0, 2), - wrappedExpect ); }; @@ -1936,7 +1916,7 @@ expectPrototype._callInNestedContext = function (callback) { } else { result = makePromise.resolve(result); } - return this.addAdditionalPromiseMethods(result, this.execute, this.subject); + return this.addAdditionalPromiseMethods(result, this.subject); } catch (e) { if (e && e._isUnexpected) { const wrappedError = new UnexpectedError(this, e);