Merge branch '3.99' into 4.0
This commit is contained in:
@@ -440,4 +440,47 @@ describe('Env', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("deprecates access to 'this' in describes", function() {
|
||||
jasmine.getEnv().requireProxy();
|
||||
var msg = "Access to 'this' in describe functions is deprecated.",
|
||||
ran = false;
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
expect(this.description).toEqual('a suite');
|
||||
expect(env.deprecated).toHaveBeenCalledWith(msg);
|
||||
env.deprecated.calls.reset();
|
||||
|
||||
this.foo = 1;
|
||||
expect(env.deprecated).toHaveBeenCalledWith(msg);
|
||||
expect(this.foo).toEqual(1);
|
||||
env.deprecated.calls.reset();
|
||||
|
||||
expect(this.getFullName()).toEqual('a suite');
|
||||
expect(env.deprecated).toHaveBeenCalledWith(msg);
|
||||
env.deprecated.calls.reset();
|
||||
|
||||
env.it('has a spec');
|
||||
ran = true;
|
||||
});
|
||||
|
||||
expect(ran).toBeTrue();
|
||||
});
|
||||
|
||||
// TODO: Remove this in the next major version. Suites were never meant to be
|
||||
// exposed via describe 'this' in >= 2.0, and user code should not rely on it.
|
||||
// This spec is just here to make sure we don't break user code that *does*
|
||||
// rely on it in older browsers (without Proxy) while deprecating it.
|
||||
it("sets 'this' to the Suite in describes", function() {
|
||||
var suiteThis;
|
||||
spyOn(env, 'deprecated');
|
||||
|
||||
env.describe('a suite', function() {
|
||||
suiteThis = this;
|
||||
env.it('has a spec');
|
||||
});
|
||||
|
||||
expect(suiteThis).toBeInstanceOf(jasmineUnderTest.Suite);
|
||||
});
|
||||
});
|
||||
|
||||
17
spec/helpers/checkForProxy.js
Normal file
17
spec/helpers/checkForProxy.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/* eslint-disable compat/compat */
|
||||
(function(env) {
|
||||
function hasProxyConstructor() {
|
||||
try {
|
||||
new Proxy({}, {});
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
env.requireProxy = function() {
|
||||
if (!hasProxyConstructor()) {
|
||||
env.pending('Environment does not support Proxy');
|
||||
}
|
||||
};
|
||||
})(jasmine.getEnv());
|
||||
@@ -21,6 +21,7 @@ module.exports = {
|
||||
'helpers/generator.js',
|
||||
'helpers/BrowserFlags.js',
|
||||
'helpers/checkForMap.js',
|
||||
'helpers/checkForProxy.js',
|
||||
'helpers/checkForSet.js',
|
||||
'helpers/checkForSymbol.js',
|
||||
'helpers/checkForUrl.js',
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"helpers/asyncAwait.js",
|
||||
"helpers/generator.js",
|
||||
"helpers/checkForMap.js",
|
||||
"helpers/checkForProxy.js",
|
||||
"helpers/checkForSet.js",
|
||||
"helpers/checkForSymbol.js",
|
||||
"helpers/checkForUrl.js",
|
||||
|
||||
Reference in New Issue
Block a user