Allow generator functions to be passed to .and.callFake

Fixes #1848.
This commit is contained in:
Steve Gravrock
2020-08-29 13:05:57 -07:00
parent e0eb4755cb
commit 53d8073707
7 changed files with 57 additions and 2 deletions

22
spec/helpers/generator.js Normal file
View File

@@ -0,0 +1,22 @@
(function(env) {
function getGeneratorFuncCtor() {
try {
eval('var func = function*() {}');
} catch (e) {
return null;
}
return Object.getPrototypeOf(func).constructor;
}
env.makeGeneratorFunction = function(text) {
var GeneratorFunction = getGeneratorFuncCtor();
return new GeneratorFunction(text || '');
};
env.requireGeneratorFunctions = function() {
if (!getGeneratorFuncCtor()) {
env.pending('Environment does not support generator functions');
}
};
})(jasmine.getEnv());