From 4e96514634e672e3f85276b3884a87a1e0be6897 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sat, 7 Aug 2021 12:01:44 -0700 Subject: [PATCH] Deprecated the Promise config setting 4.0 will only support environments that have native promises, so there will no longer be a need for a user-supplied promise library --- lib/jasmine-core/jasmine.js | 7 +++++++ spec/core/EnvSpec.js | 6 ++++++ spec/core/SpySpec.js | 1 + src/core/Env.js | 7 +++++++ 4 files changed, 21 insertions(+) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 67d2f066..5c645b58 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1175,6 +1175,8 @@ getJasmineRequireObj().Env = function(j$) { * @since 3.5.0 * @type function * @default undefined + * @deprecated In a future version, Jasmine will ignore the Promise config + * property and always create native promises instead. */ Promise: undefined, /** @@ -1331,6 +1333,11 @@ getJasmineRequireObj().Env = function(j$) { typeof configuration.Promise.reject === 'function' ) { customPromise = configuration.Promise; + self.deprecated( + 'The `Promise` config property is deprecated. Future versions ' + + 'of Jasmine will create native promises even if the `Promise` ' + + 'config property is set. Please remove it.' + ); } else { throw new Error( 'Custom promise library missing `resolve`/`reject` functions' diff --git a/spec/core/EnvSpec.js b/spec/core/EnvSpec.js index 9ebbda0d..a01c7ba8 100644 --- a/spec/core/EnvSpec.js +++ b/spec/core/EnvSpec.js @@ -399,11 +399,17 @@ describe('Env', function() { }); it('can be configured with a custom library', function() { + spyOn(env, 'deprecated'); var myLibrary = { resolve: jasmine.createSpy(), reject: jasmine.createSpy() }; env.configure({ Promise: myLibrary }); + expect(env.deprecated).toHaveBeenCalledWith( + 'The `Promise` config property is deprecated. Future versions of ' + + 'Jasmine will create native promises even if the `Promise` config ' + + 'property is set. Please remove it.' + ); }); it('cannot be configured with an invalid promise library', function() { diff --git a/spec/core/SpySpec.js b/spec/core/SpySpec.js index 97fc9544..bbe86a66 100644 --- a/spec/core/SpySpec.js +++ b/spec/core/SpySpec.js @@ -271,6 +271,7 @@ describe('Spies', function() { reject: jasmine.createSpy() }; customPromise.resolve.and.returnValue('resolved'); + spyOn(env, 'deprecated'); env.configure({ Promise: customPromise }); var spy = env.createSpy('foo').and.resolveTo(42); diff --git a/src/core/Env.js b/src/core/Env.js index 38471f96..23dd507d 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -137,6 +137,8 @@ getJasmineRequireObj().Env = function(j$) { * @since 3.5.0 * @type function * @default undefined + * @deprecated In a future version, Jasmine will ignore the Promise config + * property and always create native promises instead. */ Promise: undefined, /** @@ -293,6 +295,11 @@ getJasmineRequireObj().Env = function(j$) { typeof configuration.Promise.reject === 'function' ) { customPromise = configuration.Promise; + self.deprecated( + 'The `Promise` config property is deprecated. Future versions ' + + 'of Jasmine will create native promises even if the `Promise` ' + + 'config property is set. Please remove it.' + ); } else { throw new Error( 'Custom promise library missing `resolve`/`reject` functions'