diff --git a/e2e/generator-mock/__tests__/generatorMock.test.js b/e2e/generator-mock/__tests__/generatorMock.test.js index f34730b014c3..8da54d3f63f6 100644 --- a/e2e/generator-mock/__tests__/generatorMock.test.js +++ b/e2e/generator-mock/__tests__/generatorMock.test.js @@ -12,3 +12,7 @@ const methods = require('../index'); test('mock works with generator', () => { expect(methods.generatorMethod).toBeDefined(); }); + +test('mock works with asyncGenerator', () => { + expect(methods.asyncGeneratorMethod).toBeDefined(); +}); diff --git a/e2e/generator-mock/index.js b/e2e/generator-mock/index.js index 03da7dc17eda..9bc2c6208c40 100644 --- a/e2e/generator-mock/index.js +++ b/e2e/generator-mock/index.js @@ -9,4 +9,9 @@ function* generatorMethod() { yield 42; } +async function* asyncGeneratorMethod() { + yield 42; +} + module.exports.generatorMethod = generatorMethod; +module.exports.asyncGeneratorMethod = asyncGeneratorMethod; diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 2ed41294e06b..382074187b25 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -304,7 +304,8 @@ function getType(ref?: unknown): MockFunctionMetadataType | null { if ( typeName === 'Function' || typeName === 'AsyncFunction' || - typeName === 'GeneratorFunction' + typeName === 'GeneratorFunction' || + typeName === 'AsyncGeneratorFunction' ) { return 'function'; } else if (Array.isArray(ref)) { @@ -347,7 +348,8 @@ function isReadonlyProp(object: any, prop: string): boolean { return ( typeName === 'Function' || typeName === 'AsyncFunction' || - typeName === 'GeneratorFunction' + typeName === 'GeneratorFunction' || + typeName === 'AsyncGeneratorFunction' ); }