Skip to content

Commit

Permalink
feat: add auto-mock support for async generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hewitt committed Feb 12, 2021
1 parent 42f78d4 commit eb078bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions e2e/generator-mock/__tests__/generatorMock.test.js
Expand Up @@ -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();
});
5 changes: 5 additions & 0 deletions e2e/generator-mock/index.js
Expand Up @@ -9,4 +9,9 @@ function* generatorMethod() {
yield 42;
}

async function* asyncGeneratorMethod() {
yield 42;
}

module.exports.generatorMethod = generatorMethod;
module.exports.asyncGeneratorMethod = asyncGeneratorMethod;
6 changes: 4 additions & 2 deletions packages/jest-mock/src/index.ts
Expand Up @@ -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)) {
Expand Down Expand Up @@ -347,7 +348,8 @@ function isReadonlyProp(object: any, prop: string): boolean {
return (
typeName === 'Function' ||
typeName === 'AsyncFunction' ||
typeName === 'GeneratorFunction'
typeName === 'GeneratorFunction' ||
typeName === 'AsyncGeneratorFunction'
);
}

Expand Down

0 comments on commit eb078bf

Please sign in to comment.