Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unhack
  • Loading branch information
papandreou committed May 31, 2022
commit 638162c663c0d54905d15ffda31c43667af599f9
87 changes: 41 additions & 46 deletions lib/createTopLevelExpect.js
Original file line number Diff line number Diff line change
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