Skip to content

Commit

Permalink
Unhack
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 30, 2022
1 parent 315f9a8 commit 0cabe00
Showing 1 changed file with 41 additions and 46 deletions.
87 changes: 41 additions & 46 deletions lib/createTopLevelExpect.js
Expand Up @@ -1461,15 +1461,14 @@ expectPrototype._createWrappedExpect = function (
for (let i = 2; i < arguments.length; i += 1) {
args[i - 2] = arguments[i];
}
return wrappedExpect._callInNestedContext(
() =>
parentExpect._executeExpect(
context.child(),
subject,
testDescriptionString,
args,
wrappedExpect.flags
).result
return wrappedExpect._callInNestedContext(() =>
parentExpect._executeExpect(
context.child(),
subject,
testDescriptionString,
args,
wrappedExpect.flags
)
);
}

Expand Down Expand Up @@ -1573,20 +1572,39 @@ expectPrototype._executeExpect = function (
);

if (assertionRule.expect && assertionRule.expect !== this._topLevelExpect) {
return {
result: assertionRule.expect._expect(context, [
subject,
testDescriptionString,
...args,
]),
wrappedExpect,
};
return assertionRule.expect._expect(context, [
subject,
testDescriptionString,
...args,
]);
}

return {
result: oathbreaker(assertionRule.handler(wrappedExpect, subject, ...args)),
wrappedExpect,
};
let result = oathbreaker(
assertionRule.handler(wrappedExpect, subject, ...args)
);

if (utils.isPromise(result)) {
result = wrapPromiseIfNecessary(result);
if (result.isPending()) {
result = result.then(undefined, (e) => {
if (e && e._isUnexpected && context.level === 0) {
this.setErrorMessage(e);
}
throw e;
});
this.notifyPendingPromise(result);
}
} else {
result = makePromise.resolve(result);
}
// Her mangler vi wrappedExpect?
return wrappedExpect.addAdditionalPromiseMethods(
result,
this,
subject,
Array.prototype.slice.call(args, 0, 2),
wrappedExpect
);
};

expectPrototype._camelCaser = function (context, subjectType, subject) {
Expand Down Expand Up @@ -1644,34 +1662,13 @@ expectPrototype._expect = function (context, args, forwardedFlags) {
}

try {
let { result, wrappedExpect } = this._executeExpect(
return this._executeExpect(
context,
subject,
testDescriptionString,
Array.prototype.slice.call(args, 2),
forwardedFlags
);
if (utils.isPromise(result)) {
result = wrapPromiseIfNecessary(result);
if (result.isPending()) {
result = result.then(undefined, (e) => {
if (e && e._isUnexpected && context.level === 0) {
this.setErrorMessage(e);
}
throw e;
});
this.notifyPendingPromise(result);
}
} else {
result = makePromise.resolve(result);
}
return wrappedExpect.addAdditionalPromiseMethods(
result,
this,
subject,
Array.prototype.slice.call(args, 0, 2),
wrappedExpect
);
} catch (e) {
if (e && e._isUnexpected) {
let newError = e;
Expand Down Expand Up @@ -1951,8 +1948,6 @@ expectPrototype._callInNestedContext = function (callback) {
};

expectPrototype.shifty = function (subject, args, rest, legacyMode) {
this._assertWrappedExpect();

const nextArgumentType = this.findTypeOf(rest[0]);
if (legacyMode) {
// Legacy
Expand Down Expand Up @@ -1991,7 +1986,7 @@ expectPrototype.shifty = function (subject, args, rest, legacyMode) {
}
);
} else if (nextArgumentType.is('string')) {
return this.execute(subject, ...rest);
return this(subject, ...rest);
} else {
return subject;
}
Expand Down

0 comments on commit 0cabe00

Please sign in to comment.