Add .asyncGenerator and .asyncGeneratorFunction detection
This commit is contained in:
parent
aeb3f74d65
commit
b90db352a3
2 changed files with 50 additions and 2 deletions
46
test/test.ts
46
test/test.ts
|
|
@ -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']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue