Fixed pending() for async/promise-returning specs
Fixes #1449. Fixes #1450.
This commit is contained in:
@@ -4353,7 +4353,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
var maybeThenable = queueableFn.fn.call(self.userContext);
|
||||
|
||||
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
||||
maybeThenable.then(next, next.fail);
|
||||
maybeThenable.then(next, onPromiseRejection);
|
||||
completedSynchronously = false;
|
||||
return { completedSynchronously: false };
|
||||
}
|
||||
@@ -4375,6 +4375,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
errored = true;
|
||||
}
|
||||
|
||||
function onPromiseRejection(e) {
|
||||
onException(e);
|
||||
next();
|
||||
}
|
||||
|
||||
function handleException(e, queueableFn) {
|
||||
onException(e);
|
||||
if (!self.catchException(e)) {
|
||||
|
||||
@@ -375,27 +375,31 @@ describe("QueueRunner", function() {
|
||||
expect(onComplete).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("fails the function when the promise is rejected", function() {
|
||||
it("handles a rejected promise like an unhandled exception", function() {
|
||||
var promise = new StubPromise(),
|
||||
queueableFn1 = { fn: function() {
|
||||
setTimeout(function() { promise.rejectHandler('foo'); }, 100);
|
||||
setTimeout(function() {
|
||||
debugger;
|
||||
promise.rejectHandler('foo')
|
||||
}, 100);
|
||||
return promise;
|
||||
} },
|
||||
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||
failFn = jasmine.createSpy('fail'),
|
||||
onExceptionCallback = jasmine.createSpy('on exception callback'),
|
||||
queueRunner = new jasmineUnderTest.QueueRunner({
|
||||
queueableFns: [queueableFn1, queueableFn2],
|
||||
fail: failFn
|
||||
onException: onExceptionCallback
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(failFn).not.toHaveBeenCalled();
|
||||
expect(onExceptionCallback).not.toHaveBeenCalled();
|
||||
expect(queueableFn2.fn).not.toHaveBeenCalled();
|
||||
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(failFn).toHaveBeenCalledWith('foo');
|
||||
expect(onExceptionCallback).toHaveBeenCalledWith('foo');
|
||||
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1485,6 +1485,7 @@ describe("Env integration", function() {
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
var specStatus = reporter.specDone.calls.argsFor(0)[0];
|
||||
|
||||
expect(specStatus.status).toBe('pending');
|
||||
expect(specStatus.pendingReason).toBe('with a message');
|
||||
|
||||
done();
|
||||
@@ -1499,6 +1500,34 @@ describe("Env integration", function() {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('should report pending spec messages from async functions', function(done) {
|
||||
jasmine.getEnv().requireAsyncAwait();
|
||||
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||
'specDone',
|
||||
'jasmineDone'
|
||||
]);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
var specStatus = reporter.specDone.calls.argsFor(0)[0];
|
||||
|
||||
expect(specStatus.status).toBe('pending');
|
||||
expect(specStatus.pendingReason).toBe('with a message');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.it('will be pending', async function() {
|
||||
debugger;
|
||||
env.pending('with a message');
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('should report using fallback reporter', function(done) {
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||
|
||||
@@ -125,7 +125,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
var maybeThenable = queueableFn.fn.call(self.userContext);
|
||||
|
||||
if (maybeThenable && j$.isFunction_(maybeThenable.then)) {
|
||||
maybeThenable.then(next, next.fail);
|
||||
maybeThenable.then(next, onPromiseRejection);
|
||||
completedSynchronously = false;
|
||||
return { completedSynchronously: false };
|
||||
}
|
||||
@@ -147,6 +147,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
errored = true;
|
||||
}
|
||||
|
||||
function onPromiseRejection(e) {
|
||||
onException(e);
|
||||
next();
|
||||
}
|
||||
|
||||
function handleException(e, queueableFn) {
|
||||
onException(e);
|
||||
if (!self.catchException(e)) {
|
||||
|
||||
Reference in New Issue
Block a user