Add .asyncGenerator and .asyncGeneratorFunction detection

This commit is contained in:
forresst 2019-12-27 07:59:58 +01:00
parent aeb3f74d65
commit b90db352a3
2 changed files with 50 additions and 2 deletions

View file

@ -123,7 +123,8 @@ const types = new Map<string, Test>([
function () {},
() => {},
async function () {},
function * (): unknown {}
function * (): unknown {},
async function * (): unknown {}
],
typename: TypeName.Function
}],
@ -189,6 +190,15 @@ const types = new Map<string, Test>([
],
typename: TypeName.Generator
}],
['asyncGenerator', {
is: is.asyncGenerator,
fixtures: [
(async function * () {
yield 4;
})()
],
typename: TypeName.AsyncGenerator
}],
['generatorFunction', {
is: is.generatorFunction,
fixtures: [
@ -198,6 +208,15 @@ const types = new Map<string, Test>([
],
typename: TypeName.Function
}],
['asyncGeneratorFunction', {
is: is.asyncGeneratorFunction,
fixtures: [
async function * () {
yield 4;
}
],
typename: TypeName.Function
}],
['asyncFunction', {
is: is.asyncFunction,
fixtures: [
@ -513,7 +532,7 @@ test('is.array', t => {
});
test('is.function', t => {
testType(t, 'function', ['generatorFunction', 'asyncFunction', 'boundFunction']);
testType(t, 'function', ['generatorFunction', 'asyncGeneratorFunction', 'asyncFunction', 'boundFunction']);
});
test('is.boundFunction', t => {
@ -572,10 +591,33 @@ test('is.generator', t => {
testType(t, 'generator');
});
test('is.asyncGenerator', t => {
testType(t, 'asyncGenerator');
const fixture = (async function * () {
yield 4;
})();
if (is.asyncGenerator(fixture)) {
t.true(is.function_(fixture.next));
}
});
test('is.generatorFunction', t => {
testType(t, 'generatorFunction', ['function']);
});
test('is.asyncGeneratorFunction', t => {
testType(t, 'asyncGeneratorFunction', ['function']);
const fixture = async function * () {
yield 4;
};
if (is.asyncGeneratorFunction(fixture)) {
t.true(is.function_(fixture().next));
}
});
test('is.map', t => {
testType(t, 'map', ['emptyMap']);
});