Skip to content
Permalink
Browse files

Merge 442bd37 into eb65d33

  • Loading branch information
papandreou committed Apr 21, 2019
2 parents eb65d33 + 442bd37 commit 1d962978f61f08ac0385b09fa018e6821159e6ec
@@ -0,0 +1,26 @@
var expect = require('../lib')
.clone()
.addAssertion('<any> to be a number after a (short|long) delay', function(
expect,
subject
) {
return expect.promise(function(run) {
setTimeout(
run(function() {
expect(subject, 'to be a number');
}),
expect.alternations[0] === 'short' ? 0 : 10
);
});
});

it('should succeed', () => {
return expect.promise.any({
foo: [expect('42', 'to be a number after a long delay')],
bar: expect(
[0, 1, 2],
'to have items satisfying',
expect.it('to be a number after a short delay')
)
});
});
@@ -1469,13 +1469,13 @@ expectPrototype._expect = function expect(context, args) {
if (utils.isPromise(result)) {
result = wrapPromiseIfNecessary(result);
if (result.isPending()) {
this.notifyPendingPromise(result);
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);
@@ -18,7 +18,10 @@ if (typeof jasmine === 'object') {

function isPendingOrHasUnhandledRejection(promise) {
return (
promise.isPending() || (promise.isRejected() && promise.reason().uncaught)
!promise._fulfillmentHandler0 &&
!promise._rejectionHandler0 &&
!promise._receiver0 &&
(promise.isPending() || (promise.isRejected() && promise.reason().uncaught))
);
}

@@ -119,6 +119,15 @@ if (typeof process === 'object') {
});
});

it('should not fail when an unresolved promise was used in a expect.promise.any construct', () => {
return expect(
'avoidPromiseAnyFootgunFalsePositive',
'executed through mocha'
).then(([err]) => {
expect(err, 'to be falsy');
});
});

describe('with a test suite spanning multiple files', () => {
it('should report that a promise was created, but not returned by the it block in the first test', () => {
return expect(
@@ -357,6 +366,15 @@ if (typeof process === 'object') {
});
});

it('should not fail when an unresolved promise was used in a expect.promise.any construct', () => {
return expect(
'avoidPromiseAnyFootgunFalsePositive',
'executed through jest'
).then(([err]) => {
expect(err, 'to be falsy');
});
});

describe('with a test suite spanning multiple files', () => {
it('should report that a promise was created, but not returned by the it block in the first test', () => {
return expect(

0 comments on commit 1d96297

Please sign in to comment.
You can’t perform that action at this time.