Optionally detect late promise rejections and don't report them as errors
This commit is contained in:
@@ -121,6 +121,58 @@ describe('Spec', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
describe('Late promise rejection handling', function() {
|
||||
it('is enabled when the detectLateRejectionHandling param is true', function() {
|
||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner');
|
||||
const globalErrors = jasmine.createSpyObj('globalErrors', [
|
||||
'reportUnhandledRejections'
|
||||
]);
|
||||
const setTimeout = jasmine.createSpy('setTimeout');
|
||||
const before = jasmine.createSpy('before');
|
||||
const after = jasmine.createSpy('after');
|
||||
const queueableFn = {
|
||||
fn: jasmine.createSpy('test body').and.callFake(function() {
|
||||
expect(before).toHaveBeenCalled();
|
||||
expect(after).not.toHaveBeenCalled();
|
||||
})
|
||||
};
|
||||
const spec = new jasmineUnderTest.Spec({
|
||||
queueableFn,
|
||||
setTimeout,
|
||||
beforeAndAfterFns: function() {
|
||||
return { befores: [before], afters: [after] };
|
||||
}
|
||||
});
|
||||
|
||||
spec.execute(fakeQueueRunner, globalErrors, null, false, false, true);
|
||||
|
||||
const options = fakeQueueRunner.calls.mostRecent().args[0];
|
||||
expect(options.queueableFns).toEqual([
|
||||
{ fn: jasmine.any(Function) },
|
||||
before,
|
||||
queueableFn,
|
||||
after,
|
||||
{ fn: jasmine.any(Function) },
|
||||
{
|
||||
fn: jasmine.any(Function),
|
||||
type: 'specCleanup'
|
||||
}
|
||||
]);
|
||||
|
||||
const done = jasmine.createSpy('done');
|
||||
options.queueableFns[4].fn(done);
|
||||
expect(globalErrors.reportUnhandledRejections).not.toHaveBeenCalled();
|
||||
expect(done).not.toHaveBeenCalled();
|
||||
|
||||
expect(setTimeout).toHaveBeenCalledOnceWith(jasmine.any(Function));
|
||||
setTimeout.calls.argsFor(0)[0]();
|
||||
expect(globalErrors.reportUnhandledRejections).toHaveBeenCalled();
|
||||
expect(globalErrors.reportUnhandledRejections).toHaveBeenCalledBefore(
|
||||
done
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("tells the queue runner that it's a leaf node", function() {
|
||||
const fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
||||
spec = new jasmineUnderTest.Spec({
|
||||
@@ -162,7 +214,7 @@ describe('Spec', function() {
|
||||
resultCallback: resultCallback
|
||||
});
|
||||
|
||||
spec.execute(fakeQueueRunner, 'cally-back', true);
|
||||
spec.execute(fakeQueueRunner, null, 'cally-back', true);
|
||||
|
||||
expect(fakeQueueRunner).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
@@ -245,7 +297,7 @@ describe('Spec', function() {
|
||||
resultCallback: function() {}
|
||||
});
|
||||
|
||||
spec.execute(attrs => attrs.onComplete(), done);
|
||||
spec.execute(attrs => attrs.onComplete(), null, done);
|
||||
|
||||
expect(done).toHaveBeenCalled();
|
||||
});
|
||||
@@ -264,7 +316,7 @@ describe('Spec', function() {
|
||||
spec.result.status = 'failed';
|
||||
attrs.onComplete();
|
||||
}
|
||||
spec.execute(queueRunnerFactory, done);
|
||||
spec.execute(queueRunnerFactory, null, done);
|
||||
|
||||
expect(done).toHaveBeenCalledWith(
|
||||
jasmine.any(jasmineUnderTest.StopExecutionError)
|
||||
@@ -295,7 +347,7 @@ describe('Spec', function() {
|
||||
config.onComplete();
|
||||
}
|
||||
|
||||
spec.execute(queueRunnerFactory, function() {});
|
||||
spec.execute(queueRunnerFactory, null, function() {});
|
||||
expect(duration).toBe(77000);
|
||||
});
|
||||
|
||||
@@ -309,7 +361,7 @@ describe('Spec', function() {
|
||||
resultCallback: function() {}
|
||||
});
|
||||
spec.setSpecProperty('a', 4);
|
||||
spec.execute(attrs => attrs.onComplete(), done);
|
||||
spec.execute(attrs => attrs.onComplete(), null, done);
|
||||
expect(spec.result.properties).toEqual({ a: 4 });
|
||||
});
|
||||
|
||||
@@ -665,7 +717,7 @@ describe('Spec', function() {
|
||||
config.onComplete(false);
|
||||
}
|
||||
|
||||
spec.execute(queueRunnerFactory, function() {});
|
||||
spec.execute(queueRunnerFactory, null, function() {});
|
||||
expect(resultCallback).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({ debugLogs: null }),
|
||||
undefined
|
||||
@@ -689,7 +741,7 @@ describe('Spec', function() {
|
||||
config.onComplete(false);
|
||||
}
|
||||
|
||||
spec.execute(queueRunnerFactory, function() {});
|
||||
spec.execute(queueRunnerFactory, null, function() {});
|
||||
expect(resultCallback).toHaveBeenCalled();
|
||||
expect(spec.result.debugLogs).toBeNull();
|
||||
});
|
||||
@@ -719,7 +771,7 @@ describe('Spec', function() {
|
||||
config.onComplete(true);
|
||||
}
|
||||
|
||||
spec.execute(queueRunnerFactory, function() {});
|
||||
spec.execute(queueRunnerFactory, null, function() {});
|
||||
expect(resultCallback).toHaveBeenCalledWith(
|
||||
jasmine.objectContaining({
|
||||
debugLogs: [{ message: 'msg', timestamp: timestamp }]
|
||||
|
||||
Reference in New Issue
Block a user