@@ -244,6 +244,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return j$.isA_('AsyncFunction', value);
|
||||
};
|
||||
|
||||
j$.isGeneratorFunction_ = function(value) {
|
||||
return j$.isA_('GeneratorFunction', value);
|
||||
};
|
||||
|
||||
j$.isTypedArray_ = function(value) {
|
||||
return (
|
||||
j$.isA_('Float32Array', value) ||
|
||||
@@ -8308,7 +8312,13 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @param {Function} fn The function to invoke with the passed parameters.
|
||||
*/
|
||||
SpyStrategy.prototype.callFake = function(fn) {
|
||||
if (!(j$.isFunction_(fn) || j$.isAsyncFunction_(fn))) {
|
||||
if (
|
||||
!(
|
||||
j$.isFunction_(fn) ||
|
||||
j$.isAsyncFunction_(fn) ||
|
||||
j$.isGeneratorFunction_(fn)
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
'Argument passed to callFake should be a function, got ' + fn
|
||||
);
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -168,7 +168,13 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @param {Function} fn The function to invoke with the passed parameters.
|
||||
*/
|
||||
SpyStrategy.prototype.callFake = function(fn) {
|
||||
if (!(j$.isFunction_(fn) || j$.isAsyncFunction_(fn))) {
|
||||
if (
|
||||
!(
|
||||
j$.isFunction_(fn) ||
|
||||
j$.isAsyncFunction_(fn) ||
|
||||
j$.isGeneratorFunction_(fn)
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
'Argument passed to callFake should be a function, got ' + fn
|
||||
);
|
||||
|
||||
@@ -76,6 +76,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return j$.isA_('AsyncFunction', value);
|
||||
};
|
||||
|
||||
j$.isGeneratorFunction_ = function(value) {
|
||||
return j$.isA_('GeneratorFunction', value);
|
||||
};
|
||||
|
||||
j$.isTypedArray_ = function(value) {
|
||||
return (
|
||||
j$.isA_('Float32Array', value) ||
|
||||
|
||||
Reference in New Issue
Block a user