Skip to content

Commit 4ef1622

Browse files
committed
simplify
1 parent 0cabe00 commit 4ef1622

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

lib/createTopLevelExpect.js

+10-30
Original file line numberDiff line numberDiff line change
@@ -1322,20 +1322,16 @@ expectPrototype.setErrorMessage = function (err) {
13221322

13231323
expectPrototype.addAdditionalPromiseMethods = function (
13241324
promise,
1325-
expect,
13261325
subject,
1327-
args,
1328-
wrappedExpect
13291326
) {
1327+
const stack = new Error('hey').stack;
1328+
const wrappedExpect = this;
1329+
const expect = this._topLevelExpect;
13301330
// const expect = this;
13311331
promise.and = function (...args) {
13321332
function executeAnd() {
13331333
if (expect.findTypeOf(args[0]).is('expect.it')) {
1334-
return expect.addAdditionalPromiseMethods(
1335-
args[0](subject),
1336-
expect,
1337-
subject
1338-
);
1334+
return expect.addAdditionalPromiseMethods(args[0](subject), subject);
13391335
} else {
13401336
return expect(subject, ...args);
13411337
}
@@ -1344,11 +1340,7 @@ expectPrototype.addAdditionalPromiseMethods = function (
13441340
if (this.isFulfilled()) {
13451341
return executeAnd();
13461342
} else {
1347-
return expect.addAdditionalPromiseMethods(
1348-
this.then(executeAnd),
1349-
expect,
1350-
subject
1351-
);
1343+
return expect.addAdditionalPromiseMethods(this.then(executeAnd), subject);
13521344
}
13531345
};
13541346

@@ -1359,14 +1351,13 @@ expectPrototype.addAdditionalPromiseMethods = function (
13591351
if (expect.findTypeOf(args[0]).is('expect.it')) {
13601352
return expect.addAdditionalPromiseMethods(
13611353
args[0](shiftedSubject),
1362-
expect,
13631354
subject
13641355
);
13651356
} else {
1366-
if (wrappedExpect) {
1357+
if (wrappedExpect !== expect) {
13671358
return wrappedExpect.shifty(
13681359
shiftedSubject,
1369-
wrappedExpect.args || [],
1360+
wrappedExpect.args,
13701361
[
13711362
methodName.replace(/[A-Z]/g, ($0) => ` ${$0.toLowerCase()}`),
13721363
...args,
@@ -1389,11 +1380,7 @@ expectPrototype.addAdditionalPromiseMethods = function (
13891380
if (this.isFulfilled()) {
13901381
return execute(this.value());
13911382
} else {
1392-
return expect.addAdditionalPromiseMethods(
1393-
this.then(execute),
1394-
expect,
1395-
subject
1396-
);
1383+
return expect.addAdditionalPromiseMethods(this.then(execute), subject);
13971384
}
13981385
};
13991386

@@ -1403,7 +1390,6 @@ expectPrototype.addAdditionalPromiseMethods = function (
14031390
if (expect.findTypeOf(args[0]).is('expect.it')) {
14041391
return expect.addAdditionalPromiseMethods(
14051392
args[0](subject),
1406-
expect,
14071393
subject
14081394
);
14091395
} else {
@@ -1416,7 +1402,6 @@ expectPrototype.addAdditionalPromiseMethods = function (
14161402
} else {
14171403
return expect.addAdditionalPromiseMethods(
14181404
this.then(execute),
1419-
expect,
14201405
subject
14211406
);
14221407
}
@@ -1441,9 +1426,8 @@ expectPrototype._createWrappedExpect = function (
14411426
if (arguments.length === 0) {
14421427
throw new Error('The expect function requires at least one parameter.');
14431428
} else if (arguments.length === 1) {
1444-
return wrappedExpect.addAdditionalPromiseMethods(
1429+
return parentExpect.addAdditionalPromiseMethods(
14451430
makePromise.resolve(subject),
1446-
wrappedExpect,
14471431
subject
14481432
);
14491433
} else if (typeof testDescriptionString === 'function') {
@@ -1597,13 +1581,9 @@ expectPrototype._executeExpect = function (
15971581
} else {
15981582
result = makePromise.resolve(result);
15991583
}
1600-
// Her mangler vi wrappedExpect?
16011584
return wrappedExpect.addAdditionalPromiseMethods(
16021585
result,
1603-
this,
16041586
subject,
1605-
Array.prototype.slice.call(args, 0, 2),
1606-
wrappedExpect
16071587
);
16081588
};
16091589

@@ -1936,7 +1916,7 @@ expectPrototype._callInNestedContext = function (callback) {
19361916
} else {
19371917
result = makePromise.resolve(result);
19381918
}
1939-
return this.addAdditionalPromiseMethods(result, this.execute, this.subject);
1919+
return this.addAdditionalPromiseMethods(result, this.subject);
19401920
} catch (e) {
19411921
if (e && e._isUnexpected) {
19421922
const wrappedError = new UnexpectedError(this, e);

0 commit comments

Comments
 (0)