@@ -334,6 +334,17 @@ describe('SpyStrategy', function() {
|
||||
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
||||
});
|
||||
|
||||
it('allows generator functions to be passed to callFake strategy', function() {
|
||||
jasmine.getEnv().requireGeneratorFunctions();
|
||||
|
||||
var generator = jasmine.getEnv().makeGeneratorFunction('yield "ok";'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: function() {} });
|
||||
|
||||
spyStrategy.callFake(generator);
|
||||
|
||||
expect(spyStrategy.exec().next().value).toEqual('ok');
|
||||
});
|
||||
|
||||
it('allows a return to plan stubbing after another strategy', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||
|
||||
22
spec/helpers/generator.js
Normal file
22
spec/helpers/generator.js
Normal 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());
|
||||
@@ -18,6 +18,7 @@ module.exports = {
|
||||
specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'],
|
||||
helpers: [
|
||||
'helpers/asyncAwait.js',
|
||||
'helpers/generator.js',
|
||||
'helpers/BrowserFlags.js',
|
||||
'helpers/checkForMap.js',
|
||||
'helpers/checkForSet.js',
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/asyncAwait.js",
|
||||
"helpers/generator.js",
|
||||
"helpers/checkForMap.js",
|
||||
"helpers/checkForSet.js",
|
||||
"helpers/checkForSymbol.js",
|
||||
|
||||
Reference in New Issue
Block a user